Looking at this example, http://www.datatables.net/examples/api/multi_filter_select.html, which uses columns.search() from the DataTable API, how would you 'clear' the search and show all results again when the user selects 'All' or the empty first option?
You clear the search by using an empty string as search term, without regular expression match. The individual column filtering demo is somehow a little bit misleading, since the first (unnamed) option not is "all" or "any", as one could belive, but in fact should be named "empty" or "null". If you select the first option, a regular expression search for the empty string is performed. I guess the demo is made in haste.
Modified demo where selecting the first option "clear" the search, that is selecting all :
$("#example tfoot th").each( function ( i ) {
var select = $('<select><option value="">All</option></select>')
.appendTo( $(this).empty() )
.on( 'change', function () {
var term = $(this).val()!='' ? '^'+$(this).val()+'$' : '';
table.column( i )
.search(term, true, false )
.draw();
} );
table.column( i ).data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
});
});
modified individual column filtering demo -> http://jsfiddle.net/CmMfJ/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With