how avoid getting exception jqgrid when row count 0 , filters applied. code looks this
function filtergrid(grid, siteid, buildingid, cityid, selectedtype) { var today = new date(); var dd = today.getdate(); var mm = today.getmonth() + 1; //january 0! var yyyy = today.getfullyear(); if (dd < 10) { dd = '0' + dd } if (mm < 10) { mm = '0' + mm } today = mm + '/' + dd + '/' + yyyy; if (cityid == -1) { grid.setgridparam({ search: false }); } else { var filter = { groupop: "and", rules: [{ field: "cityid", op: "eq", data: cityid}] }; if (siteid >= 0) filter = { groupop: "and", rules: [{ field: "cityid", op: "eq", data: cityid }, { field: "siteid", op: "eq", data: siteid}] }; // , { field: "buildingid", op: "eq", data: buildingid} if (buildingid >= 0) filter = { groupop: "and", rules: [{ field: "cityid", op: "eq", data: cityid }, { field: "siteid", op: "eq", data: siteid }, { field: "buildingid", op: "eq", data: buildingid}] }; if (selectedtype == "outstanding books") filter = { groupop: "and", rules: [{ field: "cityid", op: "eq", data: cityid }, { field: "siteid", op: "eq", data: siteid }, { field: "buildingid", op: "eq", data: buildingid }, { field: "isreturndatenull", op: 'eq', data: true }, { field: "duedate", op: 'gt', data: today}] }; //for filtering grid.setgridparam({ search: true, postdata: { filters: json.stringify(filter)} }); //for searching //grid.setgridparam({ search: true, postdata: { searchoper: "eq", searchfield: "status", searchstring: selectedval} }); } grid.trigger("reloadgrid"); }
the code have written works fine if datasource has no records bind grid exception, thought of getting row count hidden field on server side , on client side if row count 0 in hidden field skip searching, since datasource getting assigned jqgrid during asynchronous call hence value in hidden field not getting updated(always empty string in hiddenfield on client side) can body me how avoid getting null exception jqgrid when there no data bound it.
i found answer question. used event onsearching of jqgrid , on server side row count hidden field contains current row , if row count 0 cancel search operation.
protected void grdbooktransaction_searching(object sender, trirand.web.ui.webcontrols.jqgridsearcheventargs e) { if (string.isnullorempty(gridcount.value) || gridcount.value == "0") { e.cancel = true; } }
Comments
Post a Comment