 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
jurassicjeff
Joined: 03 Oct 2007 Posts: 16
|
Posted: Wed Oct 17, 2007 2:02 pm Post subject: sum of a column |
|
|
Hi, I am new as pear user and I would like to use structure datagrid to
display results of queries. (I am trying to work with db_table at the moment)
I have read different tutorials and I did not find answer to my question.
How can I display in the last row, results of som of a column.
Do I have to get result array of the query, calculate sum and recreate an array with a supplementary row with totals, or doest exist something easier.
How can I have different format (size , bold ) for displaying a special cell (like total).
thank you
Jeff |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Wed Oct 17, 2007 6:15 pm Post subject: |
|
|
There is no code for this because there are some many different things that users could want to do with SDG. But it's still possible. After bind(), do the following steps:
Step 1: Get the HTML_Table object:
$table = $datagrid->getRenderer()->getContainer(); // on PHP 4, you have to split this line into two lines
Step 2: Get the table footer:
$footer = $table->getFooter();
Step 3: Calculate the value
$totalValue = $db_table_object->select('total'); // 'total' needs to be defined in $sql, e.g. as 'SUM(whatever)'
Step 4: Add the value, style the cell (maybe merge cells?)
$footer-setCellContents(0, 0, $totalValue);
$footer->setCellAttributes(0, 0, array('style' => 'font-weight: bold', 'colspan' => 5));
This is just one possible way. Another one would be to use $datagrid->fill() with your HTML_Table object (that would be filled by SDG). |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|