During my question about how to re-apply the toolbar filter after the underline data is refreshed from a local js var question asked here, Oleg has provided me an solution: 1 use the combination of datatype:"local" and data:localvar.
Now I am facing a different problem which after a week I was not able to solve.
According to the Jqgrid wiki when using local datasource the default localreader looks like
The initial configuration of the localReader is the same as those from jsonReader
localReader = {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id",
userdata: "userdata",
subgrid: {root:"rows", repeatitems: true, cell:"cell"}
}
I found this is not the case. Because in every examples that i can find using dataype:"local", it always uses a straight js array in stead of an js object, looking like this:
var mydata = [
{id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"3",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"}];
I have tried using the default localReader (with repeatitems set to true) to process
var locObj = {"rows":[
{"id":0,"cell":["val1","val2","val3"]},
{"id":1,"cell":["val1","val2","val3"]}
],
"page":"1",
"total":"1",
"records":"2"
}
with datatype:"local", data:locObj
this will not work, because it wont pass the array check in the addlocaldata function. if I change the option to be datatype:"local", data:locObj.rows
I got a grid with correct number of rows but each cell has an empty value. I think that is becasue the addlocaldata function can not handle an array formatted like locObj.rows.
is there a way to actually process a json object (or string) with the datatype:"local" using the customised localreader (in stead of having to re-create an array on the client side)?
Any help is greatly appreciated.
Casbby
What you need to do is just the usage of
data: locObj.rows,
localReader: {repeatitems: true}
See the corresponding demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With