search in jqGrid

2019-08-02 07:03发布

问题:

i'm starter in jqGrid, i write this code for build jqGrid in ASP.NET

var grid = $('#list');
grid.jqGrid({
    url: 'jQGridHandler.ashx',
    postData: { ActionPage: 'CostTypes', Action: 'Fill' },
    ajaxGridOptions: { cache: false },
    direction: "rtl",
    datatype: 'json',
    height: 490,
    colNames: ['CostId', 'CostNo', 'CostName', 'Remark '],
    colModel: [
        { name: 'COST_ID', width: 100, sortable: true, search:true, editable: false,
            hidden: true, key: true, index: 'COST_ID' },
        { name: 'COST_NO', width: 100, sortable: true, editable: true },
        { name: 'COST_NAME', width: 350, sortable: true, editable: true },
        { name: 'REMARK', width: 300, sortable: true, editable: true }
    ],
    gridview: true,
    rowNum: 30,
    rowList: [30, 60, 90],
    pager: '#pager',
    sortname: 'COST_ID',
    viewrecords: true,
    rownumbers: true
});
grid.jqGrid('navGrid', '#pager', { add: false, edit: false, del: true, search: true },
    {},
    {},
    { url: "JQGridHandler.ashx?ActionPage=CostTypes&Action=Delete",
        reloadAfterSubmit: false },
    { multipleSearch: true});

when click in search icon and show search box when enter text example costNo=1 jqGrid not filter i think this action no work, please help me for implimet search in jqGrid thanks all

EDIT 01: when i add loadonce: true search work but when remove this option search don't work, please help me. thanks

回答1:

If you use loadonce: true the data will be loaded in the grid once. After that the datatype will be changed to "local" and all actions like reloading, sorting, searching (filtering) will be implemented locally without communication with the server.

If the user start searching the grid will be reloaded. If you use url: 'jQGridHandler.ashx', datatype: 'json' then the new request will be sent to the URL jQGridHandler.ashx. Some additional parameters inform the server that the data should be filtered, the _search parameter will be set to true. Because you use multipleSearch: true the rest information about the searching filter will be send in another parameter: filters. It's a string in JSON format. The format is described in the documentation. So the server have to decode the filters parameter and filter the grid data (typically one constructs WHERE part of the SELECT SQL statement based on the value of the filters parameter).

In the answer you will find the code example and can download the demo project.