I have a form to filter out data in a table. But I'm having some questions in how to pass that data to DataTables and how to refresh the table on any of the select or input change.
Here is the part of the code:
function renderDataTable(selector) {
var out = [];
var tables = jQuery(selector);
var sorting;
for ( var i=0, iLen=tables.length ; i<iLen ; i++ ){
var defaultCol = jQuery('th', tables[i]).index(jQuery(".dataTable-defaultSort",tables[i]));
if(defaultCol >= 0){
sorting = [ defaultCol, 'desc' ];
}else{
sorting = [12,'desc'];
}
var oTable2 = jQuery(tables[i]).dataTable({
"sDom": 'T<"clearfix">lfrt<"clearfix">ip',
"aaSorting": [ sorting ],
"bStateSave": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "list.php",
"iDisplayLength": 20,
"aLengthMenu": [[20, 50, 100], [20, 50, 100]],
"sPaginationType": "full_numbers",
});
out.push( oTable2 );
}
return out;
}
$(document).ready(function() {
renderDataTable("#main_table");
$("select#myVar").change(function () {
var myVar = $(this).val();
// push data to table and refresh?
});
});
Can anyone help me out here please? Thanx in advance.