Null values cannot be filtered
Null values cannot be filtered
this.api().columns([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33]).every( function () { var column = this; var select = $('<select style="border:1px solid #ced4da;height:30px"><option value="">全部</option></select>') .appendTo( $(column.footer()).empty() ) .on( 'change', function () { var val = $.fn.dataTable.util.escapeRegex( $(this).val() ); column .search( val ? '^'+val+'$' : '', true, false ) .draw(); } ); column.data().unique().sort().each( function ( d, j ) { if(column.search() === '^'+d+'$'){ select.append( '<option value="'+d+'" selected="selected">'+d+'</option>' ) } else { select.append( '<option value="'+d+'">'+d+'</option>' ) } } ); } ); },**:
There are null values and null values in my data. Other values can be filtered by drop-down, but null values and null values cannot be filtered. Is there a problem with my local code? Please help correct it.
This question has an accepted answers - jump to answer
Answers
Are the null values empty strings? If so you will need to create a search plugin to filter out empty cells. When using
search()
orcolumn().search()
with en empty string, ie""
, Datatables will use this to reset the search and display all rows. See this thread for an example of a search plugin with empty strings.If this doesn't help please provide a test case with an example of your null data so we can understand exactly what you have to offer suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thank you help,There are two kinds of null values in the database, one is no value, and the other is null,I use the drop-down selection of all fields to filter,There are many fields with null values, such as JL fields
When the current selection is null, it cannot be filtered
The
search()
andcolumn().search()
methods always use string based matching. They are not type aware sonull
itself can't be searched for using these methods. Also, for these two methods an empty string is the same as "no filter".If you need type aware filtering, you would need to create a search plug-in that would handle null values as well as empty strings and any other value you pass in.
Regards,
Allan