Server-Side processing and Parameters
Server-Side processing and Parameters
Hi,
I have a scenario where I'm using datatables to display some search results based on input that the user gives. Previously, I just did an ajaxSubmit on the form, and built up the table server-side, then converted it to a datatable on the client side. But this doesn't work well if the results are large.
So, I wanted to try and use the server-side processing with datatables so that the rendering of the table is faster. However, I wasn't sure how to use the search parameters given by the user with the server-processing code. I thought that I might be able to pass them using the sAjaxSource property, but that didn't seem to work.
Any suggestions?
Thanks,
Jonathan
I have a scenario where I'm using datatables to display some search results based on input that the user gives. Previously, I just did an ajaxSubmit on the form, and built up the table server-side, then converted it to a datatable on the client side. But this doesn't work well if the results are large.
So, I wanted to try and use the server-side processing with datatables so that the rendering of the table is faster. However, I wasn't sure how to use the search parameters given by the user with the server-processing code. I thought that I might be able to pass them using the sAjaxSource property, but that didn't seem to work.
Any suggestions?
Thanks,
Jonathan
This discussion has been closed.
Replies
If you want to pass custom parameters to the server-side, you can use a custom 'data passing' function and add information to the data object sent to the server. An example of this can bee seen here: http://datatables.net/1.5-beta/examples/server_side/custom_vars.html
Regards,
Allan
Thanks for your response. I'm using your sample, but I don't seem to be getting any results back, so I'm not sure if I'm misunderstanding what the code is doing. Here's my code:
[code]
$("#SearchTable").dataTable({
"aaSorting": [[1, "asc"]],
"iDisplayLength": 25,
"bServerSide": true,
"sAjaxSource": "Search/SearchAction.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name" : "LastName", "value" : "$('#LastName').val()" } );
$.getJSON( sSource, aoData, function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
fnCallback(json);
});
},
});
[/code]
So, I want to be able to call the server-side processing php code in SearchAction.php and pass it the value from the "LastName" text input.
Any suggestions?
Jonathan
I think you are almost there! The problem is that you are passing the string "$('#LastName').val()", rather than evaluating that expression. Try this instead:
[code]
aoData.push( { "name" : "LastName", "value" : $('#LastName').val() } );
[/code]
Regards,
Allan
Can anyone point out my error?
[code]
oTableSearch = $('#search-results').dataTable({
"bJQueryUI": true,
"bServerSide": true,
"sAjaxSource": "/nests/notinnest",
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name" : "iNestId", "value" : "" } );
$.getJSON( sSource, aoData, function (json) {fnCallback(json);
});
});
});
[/code]
If not i sugest you download it.
Then from the console you can view the HTTP request, which shows you the headers and the responce.
But for your question you can also look at the parameters that get passed to the server.
Its a little off topic for this forum, but i used it to get my datatables working.
http://usmanshabbir.blogspot.com/2010/12/extending-jquery-datatable-with-server.html