如何在jqGrid中禁用所选列的搜索选项?

时间:2014-08-26 07:28:00

标签: jquery jqgrid jqgrid-php

我有一个带列过滤器的五列(2个整数,3个字符串列)网格。我希望搜索操作的整数值(更大,更小,相等)工作正常,我不想要字符串列的搜索操作。

我正在使用后端搜索。

我期待的是如何附加模型图像,请找到它

我想要搜索,但我不想要对包含列的字符串进行搜索操作

如何删除所选列中的搜索操作。请帮助我。

enter image description here

jQuery("#list451").jqGrid({
    url: 'localset.php',
    datatype: "json",
    height: 255,
    width: 600,
    colNames: ['Index', 'Name', 'Code', 'N Name', 'C Name'],
    colModel: [{
            name: 'item_id',
            index: 'item_id',
            width: 65,
            sorttype: 'integer',
            searchoptions: {
                sopt: ['eq', 'ne', 'le', 'lt', 'gt', 'ge']
            }
        }, {
            name: 'name',
            index: 'name',
            width: 150,
            sorttype: 'string',
            searchoptions: {
                sopt: []
            }
        }, {
            name: 'code',
            index: 'code',
            width: 150,
            sorttype: 'string',
            searchoptions: {
                sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en']
            }
        }, {
            name: 'n_name',
            index: 'n_name',
            width: 150,
            sorttype: 'string',
            searchoptions: {
                sopt: []
            }
        }, {
            name: 'c_name',
            index: 'c_name',
            width: 150,
            sorttype: 'string',
            searchoptions: {
                sopt: []
            }
        },
        rowNum: 50,
        rowTotal: 200,
        rowList: [20, 30, 50],
        loadonce: true,
        mtype: "GET",
        rownumbers: true,
        rownumWidth: 40,
        gridview: true,
        pager: '#pager451',
        sortname: 'item_id',
        viewrecords: true,
        sortorder: "asc",
        caption: "Loading data from server at once"
    }); jQuery("#list451").jqGrid('filterToolbar', {
    searchOperators: true
});

3 个答案:

答案 0 :(得分:2)

colModel 中使用search:false表示您不需要搜索的列。

<强>更新
您可以通过将搜索选项替换为搜索规则

来自定义网格中的搜索选项
searchrules:{custom:true, custom_func: fnc_myStringCheck }, search:true }   

确保 stype 是自定义方法的文本(尽管是默认情况下)和 fnc_myStringCheck 。 希望这会有所帮助。

答案 1 :(得分:1)

我觉得你的问题非常有趣,所以我准备了the demo来说明问题是如何解决的。结果如下图所示:

enter image description here

当前版本的jqGrid支持clearSearch可以为每个特定列定义,但它不支持列特定的searchOperators选项。 searchOperators只有filterToolbar个选项适用于所有列。

演示调用normalizeFilterToolbar函数,该函数使用对列定义中使用新searchOperators: false选项或只有一个操作(例如,在sopt中定义了无searchoptions,或者根本没有定义searchoptions。相应的代码看起来

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);

答案 2 :(得分:0)

静态方式

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

动态方式

colModel : [ 
                    {
                        name : 'sequenceId',
                        index : ' ',
                        sortable : true,
                        classes: 'wrap',
                        formatter: disableSearch
                    }
function disableSearch(cellvalue, options, rowObject) {
    options.colModel.search = false;
    return cellvalue;
}