jQuery DataTables: Multiple checkbox filtering
jQuery DataTables: Multiple checkbox filtering
umair_malik
Posts: 7Questions: 3Answers: 0
i'm fetching records in datatable using server side scripting which fetch record perfectly. Now i want to apply filtering record using checkboxes. these checkboxes are outside datatable. previously i was using this method to filter datatable record on client side
$(':checkbox[name="Backplane_Connector[]"]').click(function() {
var filter = '',
regexFilter = true,
smartFilter = false;
filter = $('[name="' + this.name + '"]:checked').map(function() {
return this.value;
}).toArray().join('|');
if (filter != '')
filter = '^(' + filter + ')$';
$('#example').dataTable().fnFilter(filter, 0, regexFilter, smartFilter);
});
This question has accepted answers - jump to:
This discussion has been closed.
Answers
record is coming via this code
$(document).ready(function() {
});
The best solution is to modify your query on the server-side portion based on your filters. Here is a way to dynamically send values to your server-side call.
Then every time a filter is changed, you can call
oTable.ajax.reload()
and your table will be updated based on the current filters selected.the link you provided is not displaying record of php. I'm new in using datatables and i didnot found any solution to apply filters via checkboxes :(
let me explain you briefly,
suppose i've a table with two columns name and class.
-datatable will display all the record fetched from the DB when page load.
- there are checkboxs on left side of datatable which display distinct names and classes in their values(names- jhon,joe,umair classes-1,2,3,4,....10)
requirement:-
whenever a user check a checkbox (e.g jhon), datatable must display all record where name= jhon,
he can check multiple checkboxes at a time...
some people says i've to write my own sql queries for this but i don't think its the write solution because how can i write queries if there were thousands of names and classes.
i've no idea how to do this in server side processing of datatable.. please help i need it badly!
You could make an array of checked values for your filter, the values being the name of the person you'd need to find. Something like this would handle as many names being checked as you wanted. Just build the array in JS as people check names and pass it to your server-side script.