Lukaszaq February 2016

CheckBox as jqGrid Filter

Is there any chance to use CheckBox as jqGrid Filter? Assuming, that i have field with values only 0 and 1. If checkbox will be checked then filtred value will be 1, no filtering.

Answers


Oleg February 2016

The reason, why one don't use checkboxes in the filter toolbar, is very simple: one need 3-state checkbox: checked, unchecked and not-defined:

  • "checked" state means filtering by checked (1 value in your case)
  • "unchecked" state means filtering by unchecked (0 value in your case)
  • "not-defined" state means no filtering by the column

Because of that one use mostly the property like

stype: "select", searchoptions: { sopt: ["eq", "ne"], value: ":Any;1:Yes;0:No" }

to have drop-down select element in the filter toolbar. The texts "Any", "Yes" and "No", like the values 1 and 0 can be changed to another values depend on your requirements.

UPDATED: jqGrid allows to to create custom searching interface by usage stype: "custom" and implementing custom_element and custom_value callbacks of of searchoptions See the old answer and the Searching Dialog. I would still don't recommend you to do this, because it makes things more complex without any real benefit for the user. I'm sure that some users will ask you for filtering about non-checked state: the more users the more different opinions. Select is the standard interface which know everybody and everybody understand it's meaning in the same way.

I modified the old demo to the following which demonstrates the possibility of stype: "custom" in the searching toolbar. After the click on the custom control of the filter toolbar one will see the picture like below:

enter image description here

I used in the demo of cause

Post Status

Asked in February 2016
Viewed 3,569 times
Voted 13
Answered 1 times

Search




Leave an answer