Skip to content

Instantly share code, notes, and snippets.

@dhunmoon
Created March 23, 2017 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhunmoon/b1833e881d31cf65d49cb14b7754e465 to your computer and use it in GitHub Desktop.
Save dhunmoon/b1833e881d31cf65d49cb14b7754e465 to your computer and use it in GitHub Desktop.
JS:Datatable Multiple Filters
/* 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