Filtering Question When Using Search
Filtering Question When Using Search
shawnmichael
Posts: 3Questions: 0Answers: 0
Hello,
Apologies in advance if I'm missing the obvious but is it possible to search for multiple items in one column?
For example, on the page http://www.datatables.net/
I would like to be able to enter both Firefox and Camino from the browser column and have those items appear in the search results. Is there a way to do this?
Thank you in advance and this is very very cool by the way :)
Apologies in advance if I'm missing the obvious but is it possible to search for multiple items in one column?
For example, on the page http://www.datatables.net/
I would like to be able to enter both Firefox and Camino from the browser column and have those items appear in the search results. Is there a way to do this?
Thank you in advance and this is very very cool by the way :)
This discussion has been closed.
Replies
Yes indeed this can be done. What you can do to achieve this is make use of a regular expression in your search term - for example:
oTable.fnFilter( "(Firefox)|(Camino)", 1, true );
The last parameter passed to fnFilter() tells it to treat the search string as a regular expression. This way you can build up some seriously complex filtering :-)
Hope this helps,
Allan
Our programmer is out and I'm just the person who makes the stuff look pretty.
I get the gist of what you're saying, I'm just not sure where (guessing it's the jquery.dataTables.js file) or exactly how to make the change. I'll poke around a bit more and see what I can find.
[code]
$(document).ready(function() {
var oTable = $('#example').dataTable();
oTable.fnFilter( "(Firefox)|(Camino)", 1, false );
} );
[/code]
That will initialise the DataTable, and then immediately apply the filter you are looking for (note the false as the third argument, I got it the wrong way around in my original post...).
Of course you will likely want to hook this filtering in user input elements, but this should show the basic idea of how "OR" filtering can be done on a single column.
Regards,
Allan
In your code example above, what would I put in place of Firefox and Camino... just empty parens???
You could put any Javascript variable in place of the text I have above. For example to use the input from two input boxes:
oTable.fnFilter( "("+document.getElementById('input1')+")|("+document.getElementById('input2')+")", 1, false );
Of course the expression should probably be dynamic for if you have anything in either of those inputs. But that's generally how it works.
Regards,
Allan