如何在jqgrid中应用单字段搜索

时间:2013-08-13 11:47:44

标签: jquery jqgrid

我是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");

        }
        }, {});

0 个答案:

没有答案