is there an easy/default way of adding a sum/total row in a datagrid's footer? say for example I have a QDataGrid with a list of this month's invoices and in the last row I need the total ammount of all the invoices.
Your data source is really just an array of objects / etc that you feed into the data grid. If you wish to add an additional row to that source as part of the _bind, you can. :)
if the datagrid is paginated I won't have access to all the rows, therefore unable to calculate the total value of a single column, for example.
somehow I would need access to the query that is being performed and alter in someway.
I had this problem previously, when dealing with excel exporting (I think we discussed this here in the forums) and the best solution I (following yours and others advice) came up with was writing custom queries for each of the datagrids where I needed this feature - but maybe there's no other way around.
You're mistaken. The datagrid shows everything in the datasource _regardless_ of pagination.
You use pagination to build the appropriate datasource (by adding clauses to your query). Adding an additional item after the main SQL query fills it should be trivial.
<?php $dtg->DataSource = People::LoadAll(QQ::Clause(QQ::Limit(0,10)); $usr = new People(); $user->name = "hah, I'm number 11"; $dtg->DataSource[] = $usr; ?>
- I have a table with 50 invoices (ClientId,InvoiceNumber,TotalValue)
- My datagrid shows 10 in each page
- In every page of the datagrid I need an extra row with the sum of all invoices' TotalValue;
Following your example my extra row would only show the sum for 10 invoices.
If you want the global total, you'll have to do a separate database hit to calculate it, but then adding a "invoice" with that global TotalValue to the datasource should be trivial.
Your data source is really just an array of objects / etc that you feed into the data grid. If you wish to add an additional row to that source as part of the _bind, you can. :)
if the datagrid is paginated I won't have access to all the rows, therefore unable to calculate the total value of a single column, for example.
somehow I would need access to the query that is being performed and alter in someway.
I had this problem previously, when dealing with excel exporting (I think we discussed this here in the forums) and the best solution I (following yours and others advice) came up with was writing custom queries for each of the datagrids where I needed this feature - but maybe there's no other way around.
You're mistaken. The datagrid shows everything in the datasource _regardless_ of pagination.
You use pagination to build the appropriate datasource (by adding clauses to your query). Adding an additional item after the main SQL query fills it should be trivial.
<?php$dtg->DataSource = People::LoadAll(QQ::Clause(QQ::Limit(0,10));
$usr = new People();
$user->name = "hah, I'm number 11";
$dtg->DataSource[] = $usr;
?>
VexedPanda, sorry, maybe I wasn't clear
Example:
- I have a table with 50 invoices (ClientId,InvoiceNumber,TotalValue)
- My datagrid shows 10 in each page
- In every page of the datagrid I need an extra row with the sum of all invoices' TotalValue;
Following your example my extra row would only show the sum for 10 invoices.
Am I missing something?
If you want the global total, you'll have to do a separate database hit to calculate it, but then adding a "invoice" with that global TotalValue to the datasource should be trivial.
yes, exactly what I did after reading my own comment :) thanks