Serverside processing - Refresh table header

Serverside processing - Refresh table header

galli2000galli2000 Posts: 2Questions: 0Answers: 0
edited July 2012 in DataTables 1.9
Hello,

I'm using DataTables.net with server side processing on top of Oracle.
I can retrieve the parameters from my DataTable, pass them to Oracle, and this is working OK (filtering, sorting. paging).
Now, I'd want to be able to do some filtering / sorting / paging, then move away from the page, come back and reload my DataTable like it was last time.
For that I save the _GET DataTable parameters array into a server session after setting some filtering / sorting / paging.
Then in order to reload it first time I return to my page, I use the following JS code, to read from session and change aoData on the fly:
[code]
'fnServerParams': function (aoData) {
var sEcho = aoData[0].value;
if ('1' == sEcho) {
var params = <?=json_encode(Session::read(${CTL_DATAID}, true))?>;
if (! jQuery.isEmptyObject(params)) {
aoData.length = 0; // empty array
$.each(params, function(name, value) {
aoData.push({'name': name, 'value': value});
switch (name) {
case 'sSearch_0':
$('#CO_ID').val(value);
break;
case 'sSearch_2':
$('#SERIAL_ID').val(value);
break;
case 'sSearch_3':
$('#PARTY_ID').val(value);
break;
case 'sSearch_5':
$('#ACCOUNT_ID').val(value);
break;
case 'sSearch_6':
$('#STATUS_ID').val(value);
break;
}
});
}
}
},
[/code]
This way, I'm able to reload my data the way I expect it.
BUT, I can't get the DataTable attributes to be reloaded, typically
- the paging attributes always shows page 1
- the header of the table does not show which column I sorted last time
even if the correct information is present in aoData.

How can I synchronize the DataTable presentation with aoData?

Thanks in advance.

Replies

  • galli2000galli2000 Posts: 2Questions: 0Answers: 0
    Damned,

    I've missed the bStateSave option! It does exactly what I need: save the state of a DataTable.

    So, finally the table parameters are restored automatically through this option, and I just need to refill the input / select that I use for filtering in thead, which can be done with fnInitComplete:
    [code]
    'bStateSave': true,
    'fnInitComplete': function() {
    var oSettings = this.fnSettings();
    <?php $i = 0;?>
    <?php foreach (${CTL_COLUMNS} as $columnId => $whatever) : ?>
    if (oSettings.aoPreSearchCols[<?=$i?>].sSearch.length > 0) {
    $('#<?=$columnId?>').val(oSettings.aoPreSearchCols[<?=$i?>].sSearch);
    }
    <?php $i++; ?>
    <?php endforeach; ?>
    [/code]
This discussion has been closed.