javascript - datatables and server-side processing - load on demand -


i've build simple table using datatables , connected server-side script populate table data.

above table have 2 checkboxes , 2 date selects specify filter criterias. when page loading table filled, because @ startup datatable pulling first page of data server.

i disable first initial data load, when page loaded i'll empty table, after i'll select criterias , press 'load' button data loaded.

i know how add filter criterias server params, need load data server after user click button.

below datatable script:

var mytable= $('table#mytable').datatable({     "table-layout": "fixed",     "bjqueryui": true,     "sdom": '<"h"lpr>t<"f"ip>',     "idisplaylength": 25,     "alengthmenu": [[25, 50, 100, 500], [25, 50, 100, 500]],     "bsort": false,     "spaginationtype": "full_numbers",     "bpaginate": true,     "bprocessing": true,     "bserverside": true,     "sajaxsource": "data.asmx/sales",     "fnserverdata": function(ssource, aodata, fncallback) {         var secho = aodata[0].value;         var idisplaystart = aodata[3].value;         var idisplaylength = aodata[4].value;          $.ajax({             contenttype: "application/json; charset=utf-8",             type: "post",             url: ssource,             //below parameters             data: "{'secho': '" + secho                 + "','idisplaystart': '" + idisplaystart                 + "','idisplaylength': '" + idisplaylength                 + "'}",             success: function(msg) {                 fncallback(msg.d);             },             error: function(xmlhttprequest, textstatus, errorthrown) {                 alert(xmlhttprequest.status);                 alert(xmlhttprequest.responsetext);             }         });     },     "bautowidth": false,     "aocolumns": [{             "stype": "numeric",             "mdata": "nr",             "swidth": "50px"         }, {             "stype": "string",             "mdata": "name"         }, {             "stype": "string",             "mdata": "surname"         }] }); 

you specify ideferloading parameter datatables, number of records table contains in dom, or 0 if no records.

$(document).ready(function() { $('#example').datatable( {     "bprocessing": true,     "bserverside": true,     "sajaxsource": "scripts/server_processing.php",     "ideferloading": 0 } ); } ); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -