Datatable mutiple column Range filtering
Datatable mutiple column Range filtering
I'm trying to find an example where I can do range filtering on multiple columns...I'm not trying to search for a range on multiple columns.. I want multiple columns to be range range filtered at the same time...
I'm using this example for range filtering..
https://datatables.net/examples/plug-ins/range_filtering.html
I'm using textboxes on each column to get the values and doing range filter if first cahracter is '> or '<' ..otherwise I'm doing a normal search.
Problems:
1) Whenever I range filter one column it works fine, but when I range filter on another column it clears the filter on first column and filters it on the second. I want the range filter to be applied on both columns
2) whenever I enter something in textbox and clear it out, the datatable doesn't reset..
oTable = $('#requestTable').DataTable();
oTable.columns().eq( 0 ).each( function ( ) {
$( 'thead input' ).on( 'keyup change', function () {
colIdx = $("thead input").index(this);
filter_input = this.value;
first_char = filter_input.substring(0,1);
rem_string = filter_input.substring(1);
if(first_char == "<" ) {
max = parseInt(rem_string, 10 );
requestWhse.oTable.draw();
}
else if(first_char == ">" && rem_string.length > 0){
min = parseInt(rem_string, 10 );
requestWhse.oTable.draw();
}
else if(this.value == '' || this.value == null){
requestWhse.oTable.column( $("thead input").index(this) ).search(this.value).draw();
}
else if ($.isNumeric(this.value )){
requestWhse.oTable.column( $("thead input").index(this) ).search( "^" + this.value + "$",true).draw();
}
else if (rem_string.length == 0) {
requestWhse.oTable.column( $("thead input").index(this) ).search(rem_string).draw();
}
} );
});
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var value = parseFloat( data[colIdx] ) || 0;
if ( ( isNaN( min ) && isNaN( max ) ) ||
( isNaN( min ) && value < max ) ||
( min < value && isNaN( max ) ) ||
( min < value && value < max ) )
{
return true;
}
return false;
}
);
Any suggestions on how to make range filter to work simultaneously on multiple columns??
Answers
If you want to place a range filter or range slider filter per column, you can use my yadcf plugin
range slide sample: http://yadcf-showcase.appspot.com/DOM_source.html
range sample: http://yadcf-showcase.appspot.com/multiple_tables.html
Thank you for the reply.. I'll give it a try, but this filter takes away the ability to do an exact match on the column.. I need something for '>', '<' and '=' and it is 6 digit number, so I can only accommodate one text box..
http://stackoverflow.com/questions/5223830/jquery-datatables-filter-column-with-comparison-operators
I found something that does the operand filtering but it only does it on one column..
How can we make it work on multiple columns at the same time??
I tried something like this..