Created
March 23, 2017 10:58
-
-
Save dhunmoon/b1833e881d31cf65d49cb14b7754e465 to your computer and use it in GitHub Desktop.
JS:Datatable Multiple Filters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Custom filtering function which will search data in column four between two values */ | |
$.fn.dataTable.ext.search.push( | |
function( settings, data, dataIndex ) { | |
var min = parseInt( $('#min').val(), 10 ); | |
var max = parseInt( $('#max').val(), 10 ); | |
var age = parseFloat( data[3] ) || 0; // use data for the age column | |
if ( ( isNaN( min ) && isNaN( max ) ) || | |
( isNaN( min ) && age <= max ) || | |
( min <= age && isNaN( max ) ) || | |
( min <= age && age <= max ) ) | |
{ | |
return true; | |
} | |
return false; | |
} | |
); | |
$(document).ready(function() { | |
var table = $('#example').DataTable(); | |
// Event listener to the two range filtering inputs to redraw on input | |
$('#min, #max').keyup( function() { | |
table.draw(); | |
} ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment