How to disable search opertion for seleted column in jqGrid?

拜拜、爱过 提交于 2019-12-07 09:33:46

I find your question very interesting and so I prepared the demo which shows how the problem can be solved. The results looks like on the picture below:

The current version of jqGrid support clearSearch which can be defined for every specific column, but it didn't support column specific searchOperators option. There are only searchOperators option of filterToolbar applied to all columns.

The demo calls normalizeFilterToolbar function which hide the part of searching input with the searing operation for all columns where either new searchOperators: false option are used in the column definition or where only one operation are specified (for example is no sopt are defined in searchoptions or if no searchoptions at all are defined). The corresponding code looks

var $grid = $("#list"), // the grid
    normalizeFilterToolbar = function () {
        var $self = this,
            colModel = $self.jqGrid("getGridParam", "colModel"),
            $searchToolbarColumns = $self.closest(".ui-jqgrid-view")
                .find(">.ui-jqgrid-hdiv .ui-jqgrid-htable .ui-search-toolbar>.ui-th-column"),
            cCol = colModel.length,
            iCol,
            cm;

        for (iCol = 0; iCol < cCol; iCol++) {
            cm = colModel[iCol];
            if (cm.searchoptions == null ||
                    ((cm.searchoptions.sopt == null || cm.searchoptions.sopt.length === 1) && cm.searchoptions.searchOperators !== true) ||
                    (cm.searchoptions.searchOperators === false)) {
                // hide the searching operation for the column
                $($searchToolbarColumns[iCol]).find(">div>.ui-search-table .ui-search-oper").hide();
            }
        }
    };

// create the grid
$grid.jqGrid({
    // ... the options
});

$grid.jqGrid("filterToolbar", {searchOperators: true, defaultSearch: "cn"});
normalizeFilterToolbar.call($grid);

Use search:false in your colModel for columns you dont need searching.

UPDATE
You can customize the search option in your Grid by replacing searchoptions: with searchrules

searchrules:{custom:true, custom_func: fnc_myStringCheck }, search:true }   

Make sure the stype is text (though it is by default) and fnc_myStringCheck for your custom method. Hope this helps.

static way:

colModel : [ 
                    {
                        name : 'sequenceId',
                        index : ' ',
                        search: false,
                        sortable : true,
                        classes: 'wrap'
                    }

dynamic way:

colModel : [ 
                    {
                        name : 'sequenceId',
                        index : ' ',
                        sortable : true,
                        classes: 'wrap',
                        formatter: disableSearch
                    }
function disableSearch(cellvalue, options, rowObject) {
    options.colModel.search = false;
    return cellvalue;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!