0

我是 jQgrid 的新手。我想在我的 jQgrid 中应用单字段搜索。但我不知道如何在我的 jQgrid 中应用此搜索。我不知道我从哪里开始做。我参考了文档,但我没有做什么。尽快提出建议。我的 jQgrid 代码是:

var oItemGrid = $("#ItemGrid");
        oItemGrid.jqGrid({
            url: 'WSAjax.asmx/GetDataForGrid',
            mtype: "POST",
            datatype: "json",
            ajaxGridOptions:
            {
                contentType: "application/json"
            },
            serializeGridData: function (data) {
                return JSON.stringify(data);
            },
            colNames: ['Type', 'Name', 'Desc'],
            colModel: [
                { name: 'Type', index: 'Type', width: 40 },
                { name: 'Name', index: 'Name', width: 40 },
                { name: 'Desc', index: 'Desc', width: 40, sortable: false}],
            prmNames: { page: "pageIndex", rows: "pageSize", sort: "sortIndex", order: "sortDirection", search: "_search" },
            autowidth: true,
            search: true,
            height: 'auto',
            rowNum: 10,
            rowList: [10, 20, 30, 40],
            sortname: sname,
            sortorder: sorder,
            page: pgno,
            jsonReader:
            {
                root: "d.rows",
                page: "d.page",
                total: "d.total",
                records: "d.records"
            },
            viewrecords: true,
            gridview: true,
            autoencode: true,
            ignoreCase: true,
            caption: 'Remember Sorting and Filtering Functionality',
            emptyrecords:"No records to display.",
            pager: '#IGPager',
            onPaging: function (pgButton) {
                isPaging = true;
            },
            onSortCol: function (colModel, colName, sortOrder) {
                saveSortInfoToCookie("ItemGridSortInfo", $("#ItemGrid"));
                var storeval = $.cookie("ItemGridSortInfo");
                alert("Saving sort info in cookie: " + storeval);
            },
            loadComplete: function (data) {
                if (isPaging) {
                    var pageInfo = $("#ItemGrid").jqGrid('getGridParam', 'page');
                    $.cookie("ItemGridPageInfo", pageInfo, { expires: 5 });
                    alert("Saving current page no. in cookie: " + pageInfo);
                    var pageno = $.cookie("ItemGridPageInfo");
                    alert("Reading saved page no. from cookie:" + pageno);
                    isPaging = false;
                }
            }//,
            //loadonce: true
        }).jqGrid('navGrid', '#IGPager', { edit: false, add: false, del: false }, {}, {}, {}, {}, {});
    });

我的Web服务方法如下:

[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public JQGrid GetDataForGrid(int pageIndex, int pageSize, string sortIndex, string sortDirection, bool _search, string filters)

更新我开发了如下代码,但它不起作用。

.jqGrid('navGrid', '#IGPager', { search: true, edit: false, add: false, del: false, refresh: false }, {}, {}, {}, {
            onSearch: function () {
                var postdata = oItemGrid.jqGrid('getGridParam', 'postData');
                $.extend(postdata, { filters: '', searchField: 'name', searchOper: ['eq', 'ne', 'bw', 'bn', 'in', 'ni', 'ew', 'en', 'cn', 'nc', 'nu', 'nn'], searchString: 'sValue' });
                oItemGrid.jqGrid('setGridParam', { search: 'sValue'.length>0, postData: postdata });
                oItemGrid.trigger("reloadGrid");

        }
        }, {});
4

0 回答 0