freeek freeek - 7 months ago 25
Javascript Question

Searching data is null

I am using jqGrid 4.6, but i laso tried this on latest version 5.1.0.
I have such definition of searchoptions:

loadComplete: function() {
var keys = grid.getGridParam('colModel');
for (var i=1; i<keys.length; i++) {
var cellname = keys[i].name;
grid.setColProp(cellname, {
searchoptions: {
dataUrl: 'RData_io.php?action=filter&field=' + cellname,
sopt: ['eq', 'ne', 'lt', 'gt', 'le', 'ge', 'cn', 'nc'],
postData: grid.getGridParam('postData')
}
});
}
}


dataUrl gives me correct select, and value is loaded correctly inside dropdownbox after some small amount of time.
We get something like this:
Search window

Seems fine, but, when we click the "Find" button, we have such params posted to the server:

filters:"{"groupOp":"AND","rules":[{"field":"week1","op":"eq","data":null}]}"


So, as you can see, "Pass", is not posted to server. Altough, if we change to "Fail", and then back to "Pass" - it's working fine.

Can you help me, Oleg?

Thank you,
Zakhar

UPDATE: If you are using not Free-jqGrid from Oleg, but some old version, or <= 5.1.0. You can use this trick, something same as @Oleg proposed, but as selectFilled do not let you to use option, use this instead:

selectFilled: function (options) {
$('.input-elm').change();
},

Answer

I see the problem on the demo. It's a bug in jqGrid. Thank you for the bug report!

I'll fix it tomorrow, but one can still use an additional feature of free jqGrid as the workaround. One can use selectFilled callback which trigger change event after the select is successfully loaded from dataUrl

selectFilled: function (options) {
    $(options.elem).change();
}

The corresponding searchoptions option will looks like

searchoptions: {
    clearSearch: false,
    selectFilled: function (options) {
        $(options.elem).change();
    },
    dataUrl: '/echo/html/',
    sopt: ['eq', 'ne', 'lt', 'gt', 'le', 'ge', 'cn', 'nc'],
    postData: { 
        html: "<select><option>Pass</option></select>",
        delay: 0
    }
}

One can verify that the fixed demo use correct data in the filter rules: https://jsfiddle.net/OlegKi/mxct4bdu/7/

UPDATED: I fixed the bug on GitHub sources (see the commit). Now the demo without the workaround with selectFilled: function (options) { $(options.elem).change(); } works correctly. See https://jsfiddle.net/OlegKi/mxct4bdu/8/