question re:using an external form to access datatables

question re:using an external form to access datatables

GWernerGWerner Posts: 7Questions: 0Answers: 0
edited June 2012 in DataTables 1.9
I have an external search form that I would like to use to update the content of the datatable that is using server-side processing.

html
[code][/code]

if I add the following function ... I am able to access the global search field

[code]
$('#myField').keyup(function(){
oTable.fnFilter( $(this).val() );
} );
[/code]

however, I do not simply want to filter all the results. What I would like, is to be able to pass a value to the server side processing script. from other questions, it looks like I need to add the following:

[code]
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
var testVal = $('#myField').val();
aoData.push( { "name": "test", "value": testVal } );
$.getJSON( sSource, aoData, function (json) {
fnCallback(json);
} );
}
[/code]

however ... when I do this ... all that gets passed to the server script is &test=

am I doing something wrong? did I miss a step?

Thanx

Replies

  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    That looks good to me (although I would suggest you use fnServerParams rather than fnServerData), but you need to call oTable.fnDraw() in your keyup function to cause the DataTable to redraw (and thus make the request to the server and get the value from the text field again).

    Allan
  • GWernerGWerner Posts: 7Questions: 0Answers: 0
    Thanx Allan ... that did the trick.

    As for your comment ... why is fnServerParams better to use than fnServerData? just curious.
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Simply because you don't need to add your own Ajax call to the server and can instead use the call that DataTables provides (including its error handling). Saves you 3 lines of code :-)

    Allan
This discussion has been closed.