Reputation: 4323
I'm trying to use Datatables filter function to do something simple (I thought). Based on the selected radio button, I want to exclude or include rows that have no value (i.e., are empty) for a specific column. Like so:
$("#full_table").DataTable({
initComplete: function() {
var table = $('#full_table').DataTable();
$('input[type=radio][name=exclude]').change(function() {
if (this.value == 'incblanks') {
table
.columns(0)
.search( '' )
.draw();
}
else if (this.value == 'removeblanks') {
table
.columns(0)
.search( '^(?!\s*$).+', true, false ) //THIS ISN'T WORKING
.draw();
}
});
}
});
I noted which part isn't working above. Basically, if you select Yes...then all rows are included using .search( '' )
, then, if you want to exclude the rows that have a blank for column(0), then I was trying to do a regex for any non-blank character .search( '^(?!\s*$).+', true, false )
, but this isn't working. I get no data back in the table, but no errors.
How can I fix this?
Upvotes: 1
Views: 2091
Reputation: 7361
I can confirm that your code
does actually work, check out the JSFiddle. (I used both blank and "only spaces" values to represent empty cells and they are successfully filtered out)
Possibly you are using an older version of Datatables? Empty cells seem to have illuminated some bugs in older versions. Have you upgraded to the newest?
Upvotes: 1