Disable request on page load

Disable request on page load

gabytzullgabytzull Posts: 2Questions: 0Answers: 0
edited October 2013 in General
Hello,I am new to datatables and I have a question.I have the next code:
[code]
var search;
var oTable = $(".dataTables").dataTable({
"iDisplayLength": 10,
"bProcessing": false,
"iDeferLoading": 10,
"bScrollCollapse": true,
"oLanguage": {
"sSearch": "Search all columns:",
"sZeroRecords": "Test1",
"sEmptyTable": "Test2"
},
"bServerSide": true,
"sAjaxSource": "link_here",
"aoColumns": [{"sWidth":"60%"},{"sWidth":"20%"},{"sWidth":"20%"}],
"fnServerData": function( sUrl, aoData, fnCallback ) {
if(search==true) {
aoData.push({"name":"sSearch_0", "value":$("#test_ci").val() });
$.ajax( { "url": sUrl, "type": "GET", "data": aoData, "success": fnCallback, "dataType": "json", "cache": true, "async": true } );
}
search=true;
}
});
[/code]
The table is not pre-populated on pageload and after I hit the search results appear.I receive my data correctly and everything works as expected.But when I delete everything I typed from search input 10 entries remain. I want the results to come back to initial state (0 entries).

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited October 2013
    Since you are using server-side processing, the filtering is done at the server - so you'd need to catch this condition in your script and return zero rows.

    Allan
  • gabytzullgabytzull Posts: 2Questions: 0Answers: 0
    edited October 2013
    The problem is I want only in this page this "filter".The output from ajax is used in more locations and I don't really want to modify it...Or if you have another solution it would be perfect.Thank you anyway
This discussion has been closed.