Just as you would apply default search condition for JQGrid its easy to apply multiple search conditions.
But this would need some more parameters, firstly enable multiple searches using the parameter "multipleSearch: true"
The code would as follows :-
That's it multiple filters are passed as default search condition to jqgrid web service. Handling of this is not upto web service.
Web service would get the filters data as
which if clearly formatted would be as
This would need to be converted back from json to an object to actually read the data. The following snipped explains how to form a search condition :-
Your requirements may vary, just need to customise little to achieve your requirement.
Spreadsheet: a kind of program that lets you sit at your desk and ask all kinds of neat "what if?" questions and generate thousands of numbers instead of actually working. ~Dave Barry, Claw Your Way to the Top
But this would need some more parameters, firstly enable multiple searches using the parameter "multipleSearch: true"
The code would as follows :-
$(function () { var GetFilters = function () { var filters = null; var filterData = { groupOp: "OR", rules: [] }; filterData.rules.push({ field: "id", op: "eq", data: "1" }); filterData.rules.push({ field: "id", op: "eq", data: "2" }); filterData.rules.push({ field: "id", op: "eq", data: "3" }); filterData.rules.push({ field: "id", op: "eq", data: "5" }); filters = JSON.stringify(filterData) return filters; } jQuery("#grid").jqGrid({ url:'GetDetails.asmx?team=All', datatype: "json", colNames:['ID','Name','Country','Progress'], colModel:[ {name:'id',index:'id', width:55}, {name:'Icon',index:'Icon', width:90}, {name:'name',index:'name asc, invdate', width:100}, {name:'designation',index:'designation', width:80}], rowNum:10, rowList:[10,20,30], pager: '#grid_pager', sortname: 'id', viewrecords: true, sortorder: "desc", caption:"JSON Data", serializeGridData: function (postData) { var filters = GetFilters(); if(filters != null) { postData.filters = filters; } else { if (postData.searchField === undefined) postData.searchField = null; if (postData.searchString === undefined) postData.searchString = null; if (postData.searchOper === undefined) postData.searchOper = null; if (postData.filters === undefined) postData.filters = null; } return JSON.stringify(postData); }, }).jqGrid('navGrid', '#grid_pager', { edit: false, add: false, del: false, search: true }, {}, // edit options {}, // add options {}, //del options {multipleSearch: true } ); });
That's it multiple filters are passed as default search condition to jqgrid web service. Handling of this is not upto web service.
Web service would get the filters data as
"{\"groupOp\":\"OR\",\"rules\":[{\"field\":\"id\",\"op\":\"eq\",\"data\":\"1\"},{\"field\":\"id\",\"op\":\"eq\",\"data\":\"2\"},{\"field\":\"id\",\"op\":\"eq\",\"data\":\"3\"},{\"field\":\"id\",\"op\":\"eq\",\"data\":\"5\"}]}"
which if clearly formatted would be as
"{ \"groupOp\":\"OR\", \"rules\": [ {\"field\":\"id\",\"op\":\"eq\",\"data\":\"1\"}, {\"field\":\"id\",\"op\":\"eq\",\"data\":\"2\"}, {\"field\":\"id\",\"op\":\"eq\",\"data\":\"3\"}, {\"field\":\"id\",\"op\":\"eq\",\"data\":\"5\"} ] }"
This would need to be converted back from json to an object to actually read the data. The following snipped explains how to form a search condition :-
string sCond = string.Empty; Dictionary(string, object) filtDat = (Dictionary(string,object))filters.FromJson(); string gpOp = (string)filtDat["groupOp"]; object[] ruleOp = (object[])filtDat["rules"]; for (int i = 0; i < ruleOp.Length; i++) { Dictionary(string, object) filterData = (Dictionary(string,object))ruleOp[i]; string field = (string)filterData["field"]; string op = (string)filterData["op"]; string data = (string)filterData["data"]; sCond += GetCondition(field, op, data); if (i > 0) { sCond += " " + gpOp + " "; } } return sCond;
Your requirements may vary, just need to customise little to achieve your requirement.
Spreadsheet: a kind of program that lets you sit at your desk and ask all kinds of neat "what if?" questions and generate thousands of numbers instead of actually working. ~Dave Barry, Claw Your Way to the Top