Searching data is null

不羁的心 提交于 2020-01-23 12:48:08

问题


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:

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();
},

回答1:


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/



来源:https://stackoverflow.com/questions/36776168/searching-data-is-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!