Showing computed data
Showing computed data
nskwortsow
Posts: 120Questions: 0Answers: 0
Hi,
In my table, I want to:
1) Augment one column with extra data, to be retrieved by an ajax call
2) Fill one column with HTML content returned by an ajax call
The table should remain sortable with the new content in place.
I would prefer not to make dozens of ajax calls for every table redraw, so can I do this server-side, and send the data with the other JSON?
Rephrased: can I modify the returned JSON on a row-level (for each row, I need to do calculations, and would prefer to do so server side, rather than repeated ajax requests)?
N
In my table, I want to:
1) Augment one column with extra data, to be retrieved by an ajax call
2) Fill one column with HTML content returned by an ajax call
The table should remain sortable with the new content in place.
I would prefer not to make dozens of ajax calls for every table redraw, so can I do this server-side, and send the data with the other JSON?
Rephrased: can I modify the returned JSON on a row-level (for each row, I need to do calculations, and would prefer to do so server side, rather than repeated ajax requests)?
N
This discussion has been closed.
Replies
Sort of...! Given that you are adding information for individual columns just use fnUpdate to add the information - that seems like the best solution to me.
The reason I say sort of is that DataTables 1.9- takes a copy of the data you pass in, so you can't just update the data source object, you need to specifically alter the data DataTables hold for each row (and fnUpdate is the way to do that).
> I need to do calculations, and would prefer to do so server side, rather than repeated ajax requests)?
How is your table being loaded? If its Ajax, can you not just include the calculated columns in the JSON rather than needing to make one (or many) more Ajax calls?
Allan
Ideally, I can include all the calculated columns in the JSON output.
$editor = Editor::inst( $db, 'tblPatients' )
->where( 'f_ProviderID', $_SESSION['ProviderID'] )
->fields(
Field::inst( 'PNameF' )->validator( 'Validate::required' ),
)
->join (
Join::inst('tblTreatments','object')
->join('PatientID','f_PatientID')
->set( false )
->field(
Field::inst( 'PName' ),
Field::inst( 'PCreationDate' ) // Perhaps use in future; change formatting
) )
->pkey('PatientID');
$out = $editor
->process( $_POST )
->data();
>>>>>>>> // How would I loop through the $editor variable to concatenate my strings with per-row calculations (i.e. for each row, I need to do calculations as well as add a new field). I would prefer to do this in PHP (server side) rather than through AJAX (client side).
// Send it back to the client
echo json_encode( $out );
You wouldn't - you'd loop through the `$out` variable. That is just an array of data so you can perform row level calculations on that. The data sent back to the table is in `$out['aaData']` (have a look at the Ajax return from the server and you'll see that).
Allan