Exact Match filter with more than one value in a string variable
Exact Match filter with more than one value in a string variable

I have the variable
var filtertext= '1,3,5'
I want to filter the datatable table = $('#DepotID').dataTable having the depot number exact match with variable. When I filter the data table, the record should not be displayed having the depot id value 100,303. it have to be filtered exact match of 1,2,3. Please can you help me with suggested it would be very appreciated.
With Many thanks
Pol
This discussion has been closed.
Answers
One option would be to use
column().search()
enabling the regex option and disabling the smart search option. This will allow you to have an exact match search. This example will show using regex searches:https://datatables.net/examples/api/regex.html
Kevin
Please can I ask you to give some help with code to get sorted this exact filter for the datataable. I have the string variable
string filtertext ='1,2,3'. I am trying to filter the record having the column 1 and 2 and thrree in column 1 . Please can you give some help
table.fnFilter("^"+"1", 1, true, false);
With thanks
Pol
I am trying to filter the column[1]having the value 1,2,3 on the column[1]. Any help with code would be very appreciated.
The place to start is to build a simple test case with your data. This way we can see exactly what you have.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Maybe this is the search that you want:
EDIT: More specifically this:
Kevin
I applied your code in my data table still not working. I am trying to filter the data table the person, having the age 61,66,38
https://jsfiddle.net/bptc9r80/1/
Please can you help me using the given example.
If I filter the age 6 and 30, it should filter employees having the age of 6 and 30 only. It should not filter any other rows like 16 or 60 etc. Any help would be very appreciated
The first problem is you are getting this error in the browser's console:
This FAQ explains why.
https://datatables.net/faqs/index#api
I misunderstood what data was in your column. I thought on cell in the column would have something like
1,2,3
. The example is helpful. A simple change to the regex expression should be all you need:Not the use of the or operator (
|
) between the numbers. Here is the updated example:https://jsfiddle.net/kzbov9yn/
Kevin
It is not exact match.
When I search the age '6|3|10' , now all record is displayed having the value 66,62,33,34 etc. I am looking for exact filter the record of only the age of 3 and 6 6 and 10 , If the age 3,6,10 is not there, no record should be shown
I updated the regex expression again.
https://jsfiddle.net/0emgqpa6/1/
The site is very good at helping you learn and build regex expressions:
https://regex101.com/
Kevin