DataTables custom filtering(range search) and text based search on a single table
DataTables custom filtering(range search) and text based search on a single table
Hi,
I am working on a table in which some columns are numerical and others are textual. I want to implement text-matching filter on textual columns and range search on numerical columns. I referred to https://datatables.net/examples/plug-ins/range_filtering.html and would like to implement something similar. However, the example does not show the code for implementing the text-based search. Using the above-mentioned API along with the column.search() function does not give the desired result. Could someone post the code for doing the same? TIA
This question has an accepted answers - jump to answer
Answers
Maybe you can start with an example of what you are doing so we can help.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
So, here is the JSFiddle linkhttps://jsfiddle.net/vishoo/uf4czvaj/6/
I have input boxes at the footer of the table and I want to be able to filter each column acc to the following rules.
1. If the column is text-based, then filter by text(I have commented out the code which can do that because both text searching and range filtering doesn't work together).
2. If the column is number-based, I want to be able to filter by number matching or comparison operators(i.e. I want to be able to input ">50" at the footer and get all records whose value for that column is greater than 50. Same for "<" and "=").
3. I want the searches to be cumulative.
TIA
Its a brute force example but may help you get started:
https://jsfiddle.net/gje6sncv/29/
I added
class="text"
to the text columns and enabled the search. I added `id="num" to the age footer. Added some code to the search API to parse the age footer input - you can probably come up with something more elegant. If there is an input in the age footer it will perform the search based on parsing "<", ">" or "=" from the input. Otherwise it will try the min max search.Kevin
Hey, thanks a lot for your answer. Cheers!