How do I draw() the filtered result after applying column(0).filter(....)?
How do I draw() the filtered result after applying column(0).filter(....)?
Michaeldk
Posts: 2Questions: 1Answers: 0
I'm trying to do a custom filter on a column on DataTables.
column(0).search() works fine, but .filter() does not.
In this case, it's comparing the data to a range of numbers (timestamp).
It's in typescript, since it's done in Angular 4.
const a = new Date($event[0]).getTime();
const b = new Date($event[1]).getTime();
if( b != null ) {
this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
const filteredData = dtInstance.column(i).data().filter(function ( value, index ) {
const d: number = new Date(value).getTime();
console.log('compare', a, d, b, (a <= d && d <= b));
return (a <= d && d <= b);
});
dtInstance.draw();
});
}
The console.log seems to display the correct data and the right boolean.
Any suggestion on how I update the current table with the filtered result?
I don't seem to able to find any documentation on that part.
This discussion has been closed.
Answers
The
filter()
documentation states this:filter()
will provide a set of data that can be used in your code but not to update the table display.Kevin
That's my point exactly. Can I take the data that the filter returns and render it in the table? Since search does not support "greater than" and Regex doesn't support (dynamic) ranges.
You might be able to create your own search functions like this example:
https://datatables.net/examples/api/regex.html
Or you might need to create a search plugin as described in this blog:
https://datatables.net/blog/2014-08-26
Not sure which would be easiest to accomplish what you want.
Kevin
Yes, you would need a custom search plug-in if you want to use logical evaluations such as greater than.
Allan