Using SearchBuilder to filter on checkboxes
Using SearchBuilder to filter on checkboxes
Link to test case:
http://live.datatables.net/kehodetu/1/edit
Description of problem:
In the above demo the first column of the table is a prepopulated list of check boxes. I would like to use SearchBuilder to filter based on whether a row is checked or not.
I use orthogonal data processing to convert a checked box to the filter
strings "selected" and "not selected". I then try to configure SearchBuilder to also use this same orthogonal data.
Problem: When I try to build a filter for the check boxes, I get no data displayed. There are no console errors.
Steps to reproduce, using the above test case:
1) Add condition.
2) Data = "Selected"
3) Condition = "Equals"
4) Value = "selected".
Expected outcome: one matching record found (Garrett Winters).
Actual outcome: no matching records found.
(Just to add: I realize that even if this worked, it would not be a useful solution the way it is currently written, because changes to check boxes made by users would not be visible to DataTables. But I am learning about SearchBuilder - so, one step at a time).
This question has an accepted answers - jump to answer
Answers
Yep, as you say, that wouldn't work as live DOM elements are not something that SearchBuilder considers. This example here may be of interest, as it demonstrates orthogonal data.
Colin
In my example and in the "steps to reproduce", there are no live DOM events. The checkbox is pre-populated. The user does not click any checkboxes.
I have a work-around which is to change the source data for my first column to "true" and "false" from its current form (which is a string representing the checkbox HTML). I am not seeing why my original approach does not work, though.
It would be great to understand that, if possible.
Your first test case is close. The problem is that Datatables automatic type detection for the checkbox column is setting it to
html-num
instead of string. You can set thetype
by changing your render function like this:http://live.datatables.net/kehodetu/4/edit
Or you can use
columns.type
to set the type, for example:type: 'string',
Kevin
Not only did you solve my problem, but now I have a use-case for the previously mysterious
type === 'type'
. Thank you so much!Yes, that way Datatables will type the column based on the
filter
orthogonal data. Took me awhile to understand that featureKevin
Nice, that works well!
Colin