How to search whether a value falls into a range defined by two columns?
How to search whether a value falls into a range defined by two columns?

Hi,
Suppose that a table has two columns that represent the lower and the upper bound of a range or an interval. What I'd like to achieve is a way to make the search to look for not any of the limits, which is what the columns have, but rather to look for those columns that the given value falls into the interval defined. This would have to take into account not just the cell, but the row.
For example, suppose that I have a table showing min and max of prices. When typing a value, what I want to see are the rows which min_prize <= search_value <= max_prize.
I have found some answers to the opposite problem, which is to search for the rows which one of its columns satisfy a given range of values. I'm looking for a way to do the opposite problem: the range is defined by two table columns, and using the search input, I want to look whether the given value falls into the range.
Thank you for your help,
Carlos
This question has accepted answers - jump to:
Answers
I would try creating a search plugin. In the plugin you can do the comparison of one or more columns.
Kevin
Hi kthorngren,
Thanks for the help. I have written the function, but I only get datatables calling it only when I delete the whole text of the search. This is my function:
The table uses ajax to retrieve the data:
How can I get the function be called when something is written on the input search?
Good try but I would recommend not using the global search for the range search. I would create a separate input for the range search. I put together a quick example for you:
http://live.datatables.net/sixujequ/1/edit
A good test is to type
27
into the Range search input. Hopefully the comments explain everything.Kevin
Since in my real example the table just contains ranges and not anything else, not even a column with names for the rows, I was wondering whether it is possible to just use the global input search and not pollute the page with a new inputs. No other search has sense in my context.
It seems complicated or problematic to do what I wanted. Your solution just works. I will try to just replace the global input search with the custom one, and if this doesn't work, I'll just add a new field.
Thank you!
Carlos
Kevin,
dom
saved my day. What I have done is usedom
to replace the default search with adiv
on its place, and later, by means of JQuery, to add a custom input field. The rest is just what you do with some minor changes.Thanks for your help.
Yes, you can hijack the default search and use it the way you want. Here is the updated example:
http://live.datatables.net/xuwequgu/1/edit
Note the use of
.off()
to turn off the event Datatables created.Glad you got it working.
Kevin
Just what I was looking for. Thanks!
Carlos