(FYI, I'm using jqGrid 5.)
My question is about a column filter in jqGrid. I have a field that comes back as a boolean from the server, either "true" or "false". I may have the luxury of changing this to a 0/1, but I really don't want to if I can avoid it. So, it looks like this:
{"rows":[{"rowID":47568,"field1":"some text here","isOpen":true} ...]}
In my jqGrid, I am using the "beforeProcessing" function to show that boolean as something besides "true" or "false":
beforeProcessing: function(data) {
for(var i=0, len=data.rows.length; i< len; i++) {
data.rows[i].isOpenModified = openFormatter(data.rows[i].isOpen);
}
...
function openFormatter(isOpen) {
return isOpen ? '' : 'CLOSED';
}
This has the effect of leaving the cell blank if isOpen is true, and showing 'CLOSED' if it's false. Everything is good so far.
The problem I'm having is the select field for the toolbar filter field. Here is the jqGrid column model:
colModel: [
{ name: 'field1', label: 'Stuff', width: 100},
{ name: 'isOpenModified', index:'isOpen', label: 'CLOSED',
searchoptions: { sopt:['eq'], value: ':All;" ":Open;"CLOSED":CLOSED'}, stype: 'select'},
],
This correctly shows the select box for the "CLOSED" field, but selecting anything besides "All" shows nothing.
I did try to change the isOpenModified to a 0 and 1, and then the filter select box worked, but of course I can't deliver that. My requirement is to display either empty (isOpen==true) or "CLOSED" (isOpen==false).
I feel like the solution might involve the name and index fields of the column model, but I can't pinpoint what I'm doing wrong. I appreciate your time....
index:'isOpen'property in the columnname: 'isOpenModified'? I think that you should remove it first of all. Additionally I'd recommend you to changeopenFormatterto set not empty string as the value (likereturn isOpen ? ' ' : 'CLOSED';orreturn isOpen ? ' ' : 'CLOSED';, ... instead ofreturn isOpen ? '' : 'CLOSED';) and fixvalue` ofsearchoptionscorresponds to your changes. - OlegisOpenproperty with valuestrueandfalse? Why you not just use{ name: 'isOpen', label: 'CLOSED', searchoptions: { sopt: ['eq','ne'], value: ':All;true:Open;false:CLOSED'}? - Olegformatterandunformatto display the original values in other way. I wanted to mention that jqGrid use the loaded data for filtering. I suppose that you have problems because you use trimable space as the value offalse. I suppose that the usage of' 'or' 'instead of' 'could solve your problem. - Oleg