fnServerData and bServerSide cause double-fetching

fnServerData and bServerSide cause double-fetching

ardoramorardoramor Posts: 3Questions: 0Answers: 0
edited July 2011 in General
I have instantiated a DataTable that fetches data from the server. The data is returned in a special format to allow additional layer of error handling and reporting. The table information is returned in 'data' element of the response object. The following code is used:

[code]
$('#missions').dataTable({
"bServerSide": true,
"bProcessing": true,
"bFilter": true,
"bRetrieve": true,
"bStateSave": true,
"sAjaxSource": 'missions.fzt',
"sPaginationType": "full_numbers",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax ({
type: 'post',
url: sSource,
data: aoData,
success: function (data, status, jqXHR) {
if(data.status === 0) {
fnCallback(data.data[0]);
}
else {
handleAjaxError(data, status, jqXHR);
}
},
error: function (jqXHR, status, error) {
handleAjaxError(
{
'status': 0,
'timestamp': $.now(),
'data': [],
'info': [],
'errors': [error]
},
status,
jqXHR
);
},
dataType: 'json'
});
},
...
[/code]

The problem is that it seems to make two calls to fetch the data, one after the other. If I set bServerSide: false, only one call is made. I noticed this while using Chrome's Developer tools. Is there a way to configure DataTables to make only one call to the server?

Replies

  • NympheasiNympheasi Posts: 24Questions: 0Answers: 0
    edited July 2011
    1- Open keytable.js
    2- Look for [code]_oDatatable.oApi._fnDraw( oSettings );[/code]
    3- Change it for:
    [code]
    if ( oSettings.oFeatures.bServerSide != true ){
    _oDatatable.oApi._fnDraw( oSettings );
    }
    [/code]

    Not sure if it's a good way to do it but at least it works for me.
This discussion has been closed.