JqGrid - Simple Searching With Additional Field(s)

后端 未结 2 1052
后悔当初
后悔当初 2021-01-16 03:25

I am using jqgrid and have simple searching enabled. I am wondering if there is a way to add an additional item in the select list of fields that does not exist as a column

2条回答
  •  一生所求
    2021-01-16 04:24

    The suggestion of Bethrezen with the usage of one hidden column is one way which you can use. You should only don't forget to use searchhidden: true searchoptions.

    Another way which I can suggest you can see on the demo:

    enter image description here

    In the demo I add the

    var defaultFilters = {
            "groupOp": "AND",
            "rules": [
                { "field": "All", "op": "cn", "data": ""}
            ]
        };
    ...
    $('#list').jqGrid('navGrid', '#pager', {add: false, edit: false, del: false},
        {}, {}, {},
        {
            multipleSearch: true,
            overlay: 0,
            onInitializeSearch: function ($form) {
                $form.jqFilter('addFilter', defaultFilters);
            },
            afterRedraw: function (p) {
                if (p.columns.length === $("#list")[0].p.colModel.length) {
                    p.columns.push({
                        name: 'All',
                        label: 'Any Field',
                        searchoptions: {},
                        searchrules: {},
                        searchtype: 'string',
                        inputtype: 'text'
                    });
                }
                //$(this).find('.delete-rule:first').hide();
            }
        });
    

    In the demo I extended the p.columns parameter of jqFilter method with and additional "pseudo column" 'Any Field'. It's just the idea which you can I hope adopt to your exact requirements.

提交回复
热议问题