Search based on check boxes... ?
Search based on check boxes... ?
tommi
Posts: 17Questions: 2Answers: 0
Hi there !
I have this test case :
https://live.datatables.net/cusologu/7/edit
How can I use check boxes as search criterias... something like in this test case
https://live.datatables.net/kehozene/1/edit ??
Where should I 'place' the information/words that the 'check box' search is based on ?
Thank you .
Answers
I'm not quite clear what you are asking for I'm sorry to say - I wonder if you could clarify it please. Specifically, your second example seems to be functional. Click the checkbox to hide the empty data and it filters the table. I'm not clear on what additional information you need?
Allan
Maybe this example will help:
https://live.datatables.net/vipifute/1/edit
Kevin
Yes, something like this (checkbox search, https://live.datatables.net/vipifute/1/edit ) BUT... 'applied' to a DT like this one https://live.datatables.net/cusologu/7/edit ?
Not sure what you mean by
BUT... 'applied' to a DT like this one
. Please provide more details of how you want the checkbox search applied differently than what the example shows.Kevin
Could the checkboxes be used to "refine" the search in a table like this one https://live.datatables.net/cusologu/7/edit ?
Do you mean you want to combine the checkbox search with the same columns you have select filters?
Kevin
I tried this:
https://live.datatables.net/cofudura/1/edit
For example... I want to know how many of those who know JavaScript also know HTML (or the 'reverse') ? Or how many of those who know HTML also know JQuery... ? Or... how many know all three programs ?
Use the 2nd row of searchboxes .
Suppose the last column ('Skills') has no select list in the header .
I updated the example:
https://live.datatables.net/cofudura/2/edit
I removed the first row of checkboxes and corresponding search code. The event handler has two
column().search()
calls for the same column. The second will override the first.It seems like the example works as you described. If I choose both javascript and html I see all the rows that have either. Is this what you are expecting?
If both javascript and html are selected but you don't want to show the rows with
html, javascript, jquery
then you will probably need to create a Search Plugin to parse the column data and compare to the selected checkboxes.Here is a search plugin example of the first example I posted:
https://live.datatables.net/rosahuka/1153/edit
You can update the plugin code to meet your requirements.
Kevin
You might also be interested in using select2 which allows to multiple selections. See this example:
https://live.datatables.net/jetupuda/86/edit
Kevin
When I check... for example, javascript and html I would expect to see displayed ONLY... the rows with Ashton Cox and Michael Silva (all three: Michael Silva ... and so on...) .
'In short' : on click on any checkbox : 'search' within the 'results' of the previous checked checkbox (if this exist, of course) .
[https://live.datatables.net/cofudura/2/edit ]
You are using a regex OR condition (
|
) which is why either is matching.If you want an AND condition, you need to consider order in regex as well, which is frankly a bit of a pain. However, you could just use DataTable's built in column filtering rather than building up your own regex - updated example.
Do note that the column filter is currently being used for both the checkboxes and the
select
at the top of the column. It cannot be used for both - only the last one used would be applied.If you need both, change your checkboxes to be a full search plug-in.
Allan