Editor: Custom Search Button
Editor: Custom Search Button
kmbonin
Posts: 59Questions: 16Answers: 0
Trying to add a custom button to search the records in my table and show records where column 3 is null (or blank, empty, etc).
Code for Button:
{
text: "Jobs Without Resources",
action: function (e, dt, node, config) {
table.column(3).search(null).draw();
}
},
returns zero records. Any ideas on what is wrong here and how I can fix it?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The way DataTables' filter works is that an empty string actually means no filter - so there isn't really a way using the
column().search()
method to search for an empty string.What you would need to do is have a custom search plug-in. Your button to toggle a variable that the plug-in would check - if enabled then it should filter the results. If not enabled the plug-in shouldn't filter (i.e. just return
true
for everything).Allan
So this is where I'm at...close...
It's performing the filter as desired. Now I need to find a way to clear it (another button to clear). However, once I filter the records out, it seems like they are not in the DOM anymore and I am not able to access them? I tried doing:
as an additional IF statement, but that didn't work. Any ideas?
As I mentioned above, you'd need a variable that your button can toggle (or a different button can modify if you prefer to use two buttons). Your function would need to have access to that variable.
That might be the intention with your
filterYN
parameter, but you can't callfilterResources
more than once, since it would just keep adding more filtering to the table (you aren't removing the old filter on each call).You only want to add a single function to the
ext.search
array.Allan