server side and table initialization
server side and table initialization
Hi Allan,
I have some issues with server side pagination. The page used to make a json call and received json which contained the complete entitie, then I transformed the data with javascript and populate the table. Now, I set bServerSide to true and I add the setting sAjaxSource to the table as you show on the examples. So, it gets the data, but I still need to process it. I think the right way to do it is by the fnServerData, but When I add this, the data is not retrieved from the server when the page inits. So, the workaround that I found is to add the fnInitComplete function, and make the json call in there, but the fnServerData is called twice. Is there a way to solve it?
Thanks in advance, Noelia
I have some issues with server side pagination. The page used to make a json call and received json which contained the complete entitie, then I transformed the data with javascript and populate the table. Now, I set bServerSide to true and I add the setting sAjaxSource to the table as you show on the examples. So, it gets the data, but I still need to process it. I think the right way to do it is by the fnServerData, but When I add this, the data is not retrieved from the server when the page inits. So, the workaround that I found is to add the fnInitComplete function, and make the json call in there, but the fnServerData is called twice. Is there a way to solve it?
Thanks in advance, Noelia
This discussion has been closed.
Replies
Could you possibly post your initialisation code please? It sounds like you are on the right track with using fnServerData, but what the problem is will hopefully be clearer with the code.
Regards,
Allan
[code]
currentTable = $("#currentagents").dataTable({
"sDom": "ipfrtl",
"aoColumns": [null, null, {
"bSearchable": false,
"bVisible": false
}, null, null, {
"bSearchable" : false,
"bVisible" : false
}, ],
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": http://localhost:8080/context/my_page,
"fnServerData": function ( sSource, aaData, fnCallback ) {
alert('fnServerData');
transformData(aaData.data);
}
});
[/code]
and the fnInitComplete:
[code]
"fnInitComplete": function (){
alert('fnInitComplete');
getDatafromServer();
}
[/code]
The issue is that when I first load the page, using firebug, Im not seing that the server is called unless I add the fnInitComplete (and then the fnServerData is called twice).
I hope it is clearer now.
Thanks again,
Noelia
Regards, Noelia
Unless your transformData function is doing the Ajax request/response, then you need to add this in. This example ( http://datatables.net/examples/server_side/post.html ) shows $.ajax() being used to get the data. In the callback function you can then transform your data into the formatting that DataTables requires.
Regards,
Allan