Monday 15 July 2013

jquery - jqGrid server response - different format, but it works. Why? -



jquery - jqGrid server response - different format, but it works. Why? -

i figured out jqgrid demmands server response format this:

{ "total": "xxx", "page": "yyy", "records": "zzz", "rows" : [ {"id" :"1", "cell" :["cell11", "cell12", "cell13"]}, {"id" :"2", "cell":["cell21", "cell22", "cell23"]}, ... ] }

and should utilize json reader map properties in case server response properties other jqgrid defaults.

but server response quite different yet plugin works. there no "rows" or "page" properties in our json. , total records displayed properly. server response example:

[ {"id":1,"price":3.99,"title":"foo"}, {"id":2,"price":3.99,"title":"bar"}, ... ]

how come?

thanks lot.

it's absolutely right question! first format of input info input format back upwards oldest versions of jqgrid. able read sec format (array of items) 1 have utilize tricky , not known jsonreader feature of jqgrid properties of jsonreader defined functions. next jsonreader used

class="lang-js prettyprint-override">jsonreader: { repeatitems: false, root: function (obj) { homecoming obj; }, page: function () { homecoming 1; }, total: function () { homecoming 1; }, records: function (obj) { homecoming obj.length; } }

later after introduction loadonce: true feature usage of sec input format (array of items named properties) become more usual. first format of info means server side paging, sorting , filtering/searching of data. server should homecoming only 1 page of data , inform jqgrid total number of pages using total parameter. in case of usage loadonce: true server have homecoming all info @ once. if response contains total, page , records properties, properties ignored , jqgrid calculate valued based on array of returned data.

it lot of errors usage of wrong format of input info or usage of wrong properties of jsonreader didn't corresponds input data. had thought modify code of jqgrid detect , fix definitively wrong alternative of jsonreader based on format of input data. posted suggestions pull request excepted , merged main code of jqgrid. starting version 4.4.5 (see here) jsonreader can not used in cases. because of feature both of input formats can read jqgrid without specifying additional jsonreader option.

jquery jqgrid

No comments:

Post a Comment