Custom Filter using ext.search help
Custom Filter using ext.search help
agreenspan
Posts: 11Questions: 3Answers: 0
I am trying to make a custom filter/search for multiple checked values, but nothing is happening.
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var selected_rarities = [];
if ($("#special").is(":checked")) {
selected_rarities.push(1);
};
if ($("#mythic").is(":checked")) {
selected_rarities.push(2);
};
if ($("#rare").is(":checked")) {
selected_rarities.push(3);
};
if ($("#uncommon").is(":checked")) {
selected_rarities.push(4);
};
if ($("#common").is(":checked")) {
selected_rarities.push(5);
};
if ($("#basic").is(":checked")) {
selected_rarities.push(6);
};
var rarity = parseInt( data[1] );
if ($.inArray(rarity, selected_rarities)) {
return true;
} else if (selected_rarities.length == 0) {
return true;
} else {
return false;
}
}
);
This discussion has been closed.
Answers
i got it working. The parseInt and $inArray needed some love.
Note that you can try out my yadcf plugin for datatables it has custom_func / multi_select_custom_func filter types, and they can be used with chosen/select2 too and it http://yadcf-showcase.appspot.com/DOM_source.html , all you need to provide is a custom filter function...
Not working with multiple tables now. What is the best way to search an array of values?
For using a predefined array of values you can use the 'data' property , see an example here: http://yadcf-showcase.appspot.com/multiple_tables.html (first table -> third column) read the docs (in the js file) about possible usage of it. for multi select you should use the filter_type: "multi_select" , see example on http://yadcf-showcase.appspot.com/DOM_source_chosen.html (first column), and for filtering multiple tables at once (with text input / select filter) see example http://yadcf-showcase.appspot.com/DOM_Ajax_Multiple_1.10.html (right corner above the upper table)