Server-Side processing and Parameters

Server-Side processing and Parameters

jon.bluksjon.bluks Posts: 15Questions: 0Answers: 0
edited July 2009 in General
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

Replies

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin
    Hi Jonathan,

    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
  • jon.bluksjon.bluks Posts: 15Questions: 0Answers: 0
    Hi 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
  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin
    Hi 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
  • srayner02srayner02 Posts: 15Questions: 0Answers: 0
    edited November 2010
    help, i'm trying to do a similar thing, but i have an error with my javascript syntax.
    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]
  • dobulet302dobulet302 Posts: 38Questions: 0Answers: 0
    How can you alert the data you are pushing to your sAjasSource? I am having issues on data being passed and I want to see what is being passed.
  • srayner02srayner02 Posts: 15Questions: 0Answers: 0
    edited December 2010
    dobulet, do you have the firebug plugin for firefox?
    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.
  • usmanshabbirusmanshabbir Posts: 8Questions: 0Answers: 0
    edited December 2010
    a complete server side processing with c# can be found here
    http://usmanshabbir.blogspot.com/2010/12/extending-jquery-datatable-with-server.html
This discussion has been closed.