JqGrid advanced search option "beforeSearch"?

I use the most excellent jqGrid plugin and found a lot of help on this site by doing a search, but I found a problem that I cannot solve or find a solution. This will be my first post here.

I use filterToolbar to do a search in my grid. Due to the nature of the back side, I need to interact, I unanble to use the filters that jqGrid provides, and instead I need to intercept the search and change the postdata before sending. I do this using the filterToolbar "beforeSearch" option as follows:

$("#SC_grid").jqGrid('filterToolbar', {stringResult: true, searchOnEnter: true, defaultSearch : "cn", beforeSearch: function() {
            var postData = $("#SC_grid").jqGrid('getGridParam','postData');
            var newPostData = '1=1';
            var searchData = jQuery.parseJSON(postData.filters);
            for (var iRule=0; iRule<searchData.rules.length; iRule++) {
                newPostData = newPostData + " AND " + searchData.rules[iRule].field + " LIKE '%" + searchData.rules[iRule].data + "%' ";
            }
            $("#SC_grid").jqGrid('setGridParam',{postData: { filter: newPostData, filters: ''} } );
            return false;
}});

, . , , POST . , beforeSearch() , afterShowSearch onClose . , ?

+5
1

, jqGrid , beforeSearch. , , onSearch, . , beforeSearch, trigger("reloadGrid",[{page:1}]), postData.

beforeSearch filterToolbar , , true beforeSearch. , beforeSearch .

, postData. , reloadGrid jqGrid , . . . , stackoverflow. .

postdata . , , jqGrid: beforeRequest serializeGridData. search (as this.p.search) postData (as this.p.postData). search _search true, - /. this.p.postData.

serializeGridData , , . , , ( ) .

beforeRequest serializeGridData - $.jgrid.defaults:

$.extend($.jgrid.defaults, {
         datatype: 'json', // overwrite default value of any jqGrid parameter
         serializeGridData: function(postData) {
             // your implementation
         }
});
+4

All Articles