Sums in footer with serverside data processing
Sums in footer with serverside data processing
Hi There,
as first really compliments for your work! I'm really impressed and working with Dts have teached me a lot of things.
Now comes the question ;) ....
I'm using server side.
The goal of serverside is to request only needed datas to the server to decrease traffic, load and answer time.
I would like to display in the footer the sum of the column values for the entire dataset, not only for the displayed one.
But returned "aaData" from routine "_fnAjaxUpdateDraw" only contains displayed datas.
Do you have any hint?
as first really compliments for your work! I'm really impressed and working with Dts have teached me a lot of things.
Now comes the question ;) ....
I'm using server side.
The goal of serverside is to request only needed datas to the server to decrease traffic, load and answer time.
I would like to display in the footer the sum of the column values for the entire dataset, not only for the displayed one.
But returned "aaData" from routine "_fnAjaxUpdateDraw" only contains displayed datas.
Do you have any hint?
This discussion has been closed.
Replies
Have a look at this thread, which basically asks the same question: http://datatables.net/forums/comments.php?DiscussionID=796 . Hopefully my answer there will steer you in the right direction.
Regards,
Allan
I'm sorry I asked your help when the topic were already in the forum. I were browsing a lot without finding it.
I just write what I did, basing on your suggestion, for the other forum users...
I calculated totals on server side and servered them included in json:
[code]
$sOutput = '{';
$sOutput .= '"sEcho": '.$_GET['sEcho'].', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"iMyVariable1": '.$iMyVariable1.', ';
$sOutput .= '"iMyVariable2": '.$iMyVariable2.', ';
$sOutput .= '"aaData": [ ';
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
[/code]
Then I just got them on client side:
[code]
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
//aoData.push( { "name": "more_data", "value": "my_value" } );
$.getJSON( sSource, aoData, function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
Column1Total= json.iMyVariable1;
Column2Total = json.iMyVariable1;
fnCallback(json)
} );
},
[/code]
Regards,
Nick.
No worries about asking the question again - I only found it again because I knew what I was looking for. Nice one getting ti working, and thanks very much for posting your code. I'm sure others will find it useful (and I'm sure I'll be linking to this thread in future)!
Regards,
Allan