I need to pass userData to jqgrid, but can’t find any examples of how to do this. Here’s my attempt:
Sent from the server:
{ total: 25,
page: currentpage,
userData: {foo: 'bar'},
rows: myRows }
and in jqgrid:
var data = jQuery("#grid").getGridParam('userData');
How can I send userData and read it from jqgrid?
EDIT: I know my userData is being sent, because I can see it in Fiddler. I think I’m just stuck on how to read it on the client side.
In general the usage of
userDatais pretty simple. jqGrid gives you support to send from the server any additional data which will be saved together with the jqGrid data. So if jqGrid parses the data returned from the server then it just looks foruserdata(not foruserData!!!) and save is in the internal parameteruserData.Be careful: the default property in the input data must be
userdataand NOTuserDatalike you currently have. You can overwrite the default name of input propertyjsonReader: {userdata: "userData"}orjsonReader: {userdata: "myData"}if you useuserDataormyDataas the property name with your additional data.One from the standard usage of
userDatais for displaying of the footer in the jqGrid. You can use the data for any your other propose. In another answer it is shown how to useuserDatato select the some row/rows directly after the loading data from the server.If you use
loadonce:trueparameter, the usage ofuserDatawill be a little more tricky because after the first load the data from the parameteruserDatawill be deleted, so you have to save there in the external object.Of cause you can access the
userDatawith respect ofjQuery("#grid").getGridParam('userData')only after the data are loaded. So you should do this inside of loadComplete event handle or later. By the way inside of loadComplete event handle you can access to all data which are send to you from the server throughdataparameter of loadComplete event. So you can read any other additional data and save there somewhere.