renderCell function causes Find problem

A place for users and developers of the Xataface to discuss and receive support.

renderCell function causes Find problem

Postby gbyerly » Thu Apr 21, 2011 2:56 pm

I want to display an amount field right-aligned in its column in list view. I tried the following, but it had no impact on the alignment:

Code: Select all
class tables_Tips {

   function TipAmount__display(&$record){
       return str_pad(number_format($record->val('TipAmount'), 2, '.', ','), 12, " ", STR_PAD_LEFT);
   }
}


Then i tried using the renderCell method as follows, which did not align the field values in the column properly:

Code: Select all
class tables_Tips {

    function TipAmount__renderCell( &$record ){
       return number_format($record->val('TipAmount'), 2, '.', ',');
    }
}


The only way that I could align them was to use this code:

Code: Select all
class tables_Tips {

function renderRow( &$record ){
       return '<td>'.$record->display('MeetingDate').'</td>'.
              '<td>'.$record->display('TipFrom').'</td>'.
              '<td>'.$record->display('TipTo').'</td>'.
              '<td>'.$record->display('TipType').'</td>'.
              '<td style="text-align: right;">'.$record->val('TipAmount').'</td>'.
              '<td>'.$record->display('TipDescription').'</td>';
    }
}


Two problems resulted: (1) the link functionality was lost, and (2) when I then clicked the Find tab, selected criteria from any column, and clicked FInd, I received a blank page, namely the application's index.php.

So, how do I right-align any numeric value field in list view and why did the renderRow method affect the Find adversely?
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm

Re: renderCell function causes Find problem

Postby shannah » Thu Apr 21, 2011 3:08 pm

Go with the renderCell solution, but wrap your output in a div and use style="text-align: right; width: 100%"

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: renderCell function causes Find problem

Postby gbyerly » Thu Apr 21, 2011 5:08 pm

Thanks, Steve. That took care of the numeric alignment. The issue with the Find button remains the same as previously described. In addition, the number is vertically aligned at the bottom of the cell, no matter what alignment I place in the style (middle or top as displayed below):

Code: Select all
class tables_Tips{

    function TipAmount__renderCell( &$record ){
       return '<div style="text-align: right; width: 100%; vertical-align: top;">'.number_format($record->val('TipAmount'), 2, '.', ',').'</div>';
    }
}
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm

Re: renderCell function causes Find problem

Postby shannah » Thu Apr 21, 2011 5:27 pm

For the find problem:
1. What version of Xataface/MySQL/PHP are you using?
2. What does your error log say?
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: renderCell function causes Find problem

Postby gbyerly » Thu Apr 21, 2011 5:46 pm

1. Xataface: 1.2.6 1955 is in version.txt file
MySQL: 5.0.92
PHP: 5.2.16

2. Nothing written to error log since this 2 p.m. this afternoon when I had problems with previous numeric formatting efforts.
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm

Re: renderCell function causes Find problem

Postby shannah » Thu Apr 21, 2011 5:49 pm

Are you sure there isn't another error log? If you get a blank white page that 99% of the time means a fatal error. You might also try to turn display of errors on so that you can see them in the browser window. See http://xataface.com/wiki/Troubleshooting for troubleshooting information.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: renderCell function causes Find problem

Postby gbyerly » Thu Apr 21, 2011 5:51 pm

I turned on debug mode, but no block names show on the blank page.
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm

Re: renderCell function causes Find problem

Postby gbyerly » Thu Apr 21, 2011 6:13 pm

Did not have access to hosted server for steps 1 - 2.

Step 3 produced following error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@foscms.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_jk/1.2.30 Server at www.foscms.com Port 80


Removed step 3 command from file; proceeded to step 4 and added two lines to index.php file. Received following PHP error message:

Warning: Cannot modify header information - headers already sent by (output started at /home/gbyerly/public_html/gbyerly_lhm/tables/Tips/Tips.php:20) in /home/gbyerly/public_html/x/Dataface/SearchForm.php on line 354


Contents of Tips.php file are:

Code: Select all
<?php

class tables_Tips{

//    function renderRow( &$record ){
//        return '<td>'.$record->display('MeetingDate').'</td>'.
//               '<td>'.$record->display('TipFrom').'</td>'.
//               '<td>'.$record->display('TipTo').'</td>'.
//               '<td>'.$record->display('TipType').'</td>'.
//               '<td style="text-align: right;">'.$record->val('TipAmount').'</td>'.
//               '<td>'.$record->display('TipDescription').'</td>';
//    }

    function TipAmount__renderCell( &$record ){
       //return '<td style="text-align: right;">'.$record->val('TipAmount').'</td>';
      return '<div style="text-align: right; width: 100%; vertical-align: top;">'.number_format($record->val('TipAmount'), 2, '.', ',').'</div>';
    }

}
?>
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm

Re: renderCell function causes Find problem

Postby shannah » Thu Apr 21, 2011 6:28 pm

Either check to make sure you have no returns or spaces after the closing ?> or just remove the ?> altogether. (if you leave out the closing tag it will work fine).
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: renderCell function causes Find problem

Postby gbyerly » Thu Apr 21, 2011 6:41 pm

Steve,

There was a space after the closing php tag. I removed it and the Find is working fine now. Thanks. I am new to PHP, but chose Xataface over .NET frameworks I looked at. You have done a great job. I developed a back-end for our local LeTip chapter using this framework much more quickly than I could have with ASP.NET or any related frameworks.

Now the only remaining issue is the vertical alignment of the numeric amount.

Glenn
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm

Re: renderCell function causes Find problem

Postby gbyerly » Fri Apr 22, 2011 11:41 am

I played around with a number of alternatives to get the numeric values to vertically align correctly. This worked, but even a display containing no style directive expands the row height (see attachment for a picture of the result):

Code: Select all
<?php

class tables_Tips{

//    function renderRow( &$record ){
//       $start = '<td>'.$record->display('MeetingDate').'</td>'.'<td>'.$record->display('TipFor').'</td>'.'<td>'.$record->display('TipFrom').'</td>'.'<td>'.$record->display('TipType').'</td>';
//        $end = '<td>'.$record->display('TipDescription').'</td>';
//        $val = $record->val('TipAmount');
//        if ( !isset($val) ) return $start.'<td>'.NULL.'</td>'.$end;
//          else return $start.'<td style="text-align: right; ">'.number_format($record->val('TipAmount'), 2, '.', ',').'</td>'.$end;
//    }

    function TipAmount__renderCell( &$record ){
       //return '<td style="text-align: right;">'.$record->val('TipAmount').'</td>';
       $val = $record->val('TipAmount');
       if ( !isset($val) ) return '<div style="text-align: right; ">'.NULL.'</div>';
       else return '<div style="text-align: right; font-size: 100%; padding: 0em 0em 1em 0em; ">'.number_format($record->val('TipAmount'), 2, '.', ',').'</div>';
    }

}
?>


I want all lines to appear like the lines where the tip value is null. Any ideas?
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm

Re: renderCell function causes Find problem

Postby shannah » Sun Apr 24, 2011 12:29 pm

I have made some changes to the ResultList and RelatedList classes in SVN that will make it easier to target particular columns in list view using a stylesheet. You can download the latest of these at:
http://weblite.ca/svn/dataface/core/tru ... ltList.php
and
http://weblite.ca/svn/dataface/core/tru ... edList.php

Here is an excerpt of the change log to see what was changed:
Code: Select all

------------------------------------------------------------------------
r2217 | shannah | 2011-04-24 12:29:43 -0700 (Sun, 24 Apr 2011) | 16 lines

Added css classes to result list and related list to make it easier to target them. 
This includes the following classes:
For result list <table> tag:
   1. resultList
   2. resultList--<tablename>
For result list <td> tag:
   1. resultListCell--<fieldname>
   2. resultListCell
For related list <table> tag:
   1. relatedList
   2. relatedList--<base table name>
   3. relatedList--<base table name>--<relationship name>
For related list <td> tag:
   1. resultListCell--<fieldname>
   2. resultListCell



The idea is that you can now add your own stylesheet and target particular columns easily. E.g. If you wanted to apply CSS styles to the "subtotal" column of the "invoices" table you might have a CSS style like:
Code: Select all

table.resultList--invoices td.resultListCell--subtotal {
    text-align: right;
}



-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: renderCell function causes Find problem

Postby gbyerly » Mon Apr 25, 2011 8:32 am

I added the following to a file called ploneCustom.css:

Code: Select all
table.resultList--Tips td.resultListCell--TipAmount {
        text-align: right;
    }


My table is named Tips; the column is named TipAmount. I added "@import "ploneCustom.css"" to the end of the plone.css file. I displayed the page, and the TipAmount column is still left-aligned.
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm

Re: renderCell function causes Find problem

Postby shannah » Mon Apr 25, 2011 12:16 pm

There are lots of things to check to see where it is going wrong:

1. Ensure that the ploneCustom.css is properly being picked up
2. Ensure that the table and column names are exactly correct - case sensitive
3. Ensure that the css classes are correctly included in the HTML output for both the table tags and the td tags.
4. Try adding !important to the directive to prevent it from being overridden by other CSS directives.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: renderCell function causes Find problem

Postby gbyerly » Mon Apr 25, 2011 1:45 pm

It was my fault, Steve. I had not placed the @import directive before the comments in plone.css. Duh! Once I did, it works fine.
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 34 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved