Search by Multiple Values in One Column
Search by Multiple Values in One Column
I am using Chart.js alongside DataTables so that when a section of a pie chart is selected, it filters the DataTable by that value. I want the user to be able to select multiple data sections and the values to be applied to the table at the same time as column filters.
Is there a way to either add to the current search for the same column or to clear the search and then search by multiple values at once.
E.g. 'apple' is already applied to the column as a filter. The user then selects 'orange'. The table should now show rows containing the 'apple' value or the 'orange' value in the same column.
I have it applying the filter for one value as below:
label = chart.selectedValue();
table.columns( 3 ).search(label).draw();
This question has an accepted answers - jump to answer
Answers
You will want to use regex mode. See the
search()
docs for details. You will want to use|
as an OR operator between the search terms. This example might help:http://live.datatables.net/vipifute/1/edit
NOTE: As of writing this it seems that the http://live.datatables.net environment is down. Try again later.
Kevin
@kthorngren thanks for the help! I got it working with the below Regex to include the whitespace in some of the filtering options: