jqGrid Trying to apply filter(s) on Grid creation -
i have object contains following filter string:
prefs.filters={"groupop":"and","rules":[{"field":"firstname","op":"cn","data":"max"}]}
here grid create, trying apply filters in postdata setting:
// set jquery grid $("#jqgridtable").jqgrid( { // ajax related configurations url: jqdataurl, datatype: "json", mtype: "get", autowidth: true, // configure columns colmodel: columnmodels, // grid total width , height height: "100%", // customize jqgrid post init gridcomplete: function() { cref.updatejqgridpagericons("jqgridtable"); }, // paging toppager: true, rownum: 20, rowlist: [5, 10, 20, 50, 100], viewrecords: true, // specify if "total number of records" displayed // default sorting sortname: typeof prefs.sortcol !== "undefined" ? prefs.sortcol : "lastname", sortorder: typeof prefs.sortcol !== "undefined" ? prefs.sortord : "asc", sorttype: "text", sortable: true, postdata: typeof prefs.filters !== "undefined" ? { filters: prefs.filters } : {}, //also tried this... //postdata: typeof prefs.filters !== "undefined" ? { json.stringify(filters: prefs.filters) } : {}, //remaining property settings excluded post keep short.
update: using .navgrid on grid follows:
.navgrid("#jqgridtable", { refresh: true, add: false, edit: false, del: false, refreshtitle: getrefreshtext('@model.instruction'), searchtitle: searchtext }, {}, // settings edit {}, // settings add {}, // settings delete { closeaftersearch: true, closeonescape: true, multiplesearch: true, multiplegroup: true });
when grid created, filter in postdata not applied. tried triggering reload event after initial create , did not apply filter either.
from other posts, believe i'm on correct path, appear missing something.
update after comments:
i added following code loadcomplete...
if ($("#jqgridtable").jqgrid("getgridparam", "datatype") === "json") { settimeout(function () { $("#jqgridtable").jqgrid("setgridparam", { datatype: "local", postdata: { filters: prefs.filters, sord: prefs.sortord, sidx: prefs.sortcol }, search: true }); $("#jqgridtable").trigger("reloadgrid"); }, 50); }
and retains filters. :)
however, have interesting issue side effect. can sort on columns , columns change sort asc/desc correctly, when go others , sort, sort in order loaded neither asc or desc.
you have set search: true
option of jqgrid if want filters
applied. use datatype: "json"
. means filters
send server , server code have decode filters , use there. 1 more remark. correct value postdata
{ filters: json.stringify(prefs.filters) }
.
updated: recommend upgrade latest version (4.12.1) or free jqgrid. it's fork of jgrid develop since end of 2014. use free jqgrid can change urls jqgrid files urls described in the wiki article. after can use following options:
loadonce: true, forceclientsorting: true, search: true, postdata: { filters: prefs.filters }, sortname: prefs.sortcol, sortorder: prefs.sortord
and remove loadcomplete
code posted in "update after comments" part of question. free jqgrid load data returned server, apply filter prefs.filters
locally, sort results locally , display first page of results (based on page size rownum: 20
).
the old demo loads the json data server, sort data locally , filter isfinal === 1
, display first page of results. demo uses additionally custom sorting using sortfunc
, additionalproperties
, allows saved additionally properties in local data
.
you can additionally include reloadgridoptions: { fromserver: true }
other options of navgrid
use (refresh: true, add: false, ...
). change behavior of refresh button of navigator bar reload data from server if user clicks on button. see another answer, posted today more information new options of free jqgrid , loadonce: true
.
Comments
Post a Comment