I have a dynamically created jqGrid with a custom formatter. I need to be able to access some information that is not in a grid column within the formatter. My problem is that the rowObject seems to contain only the information from the columns and nothing else, even though the JSON data has an extra attribute.
My JSON looks like:
{"rows":
[
{"cell":["637","Alice","Test","01\/01\/1980",""],"id":"637","patient_id":"637"},
...
{"cell":["635","Alice","Test","01\/01\/1980",""],"id":"635","patient_id":"635"},
],
"form_id":"3",
"records":"35",
"total":2,
"goto_patient_sidebar":"1",
"totalRecords":"35",
"dynamicFilters":"",
"listName":"Patients",
"page":1,
"recordsReturned":25,
"columns":
[
{"id":"75","field_id":"2","zmr_list_id":"13","alias":"Last Name",
"sortorder":"0","reference_field_id":"90","show_date":"0","show_time":"0"},
{"id":"76","field_id":"1","zmr_list_id":"13","alias":"First Name",
"sortorder":"1","reference_field_id":"90","show_date":"0","show_time":"0"},
{"id":"77","field_id":"25","zmr_list_id":"13","alias":"DOB",
"sortorder":"2","reference_field_id":"90","show_date":"1","show_time":"0"},
{"id":"78","field_id":"47","zmr_list_id":"13","alias":"Phone Number",
"sortorder":"3","reference_field_id":"90","show_date":"0","show_time":"0"}
]
}
For each row, I need to access the patient_id from the JSON. The data for the columns of each row is contained in the ‘cell’ for each row. The rowObject seems to contain only the information in each cell attribute of the JSON. How can I access patient_id without it being rendered in the column?
In the data the values of
patient_idare always the same as theid. I suppose that there can be different (ifpatient_idare equal toidyou can see the information in the custom formatter already). You can implement what you need in at least three ways:hidden:true) which will represent thepatient_id. You move the information about thepatient_idin the JSON input inside the"cell"array.idandpatient_idas the part ofuserdatawhich you will include in the JSON (see here for more information).dataparameter of theloadCompleteevent handle. Thedataparameter will contain full JSON data posted from the server. You can get the information which you need from thedataand save it somewhere. Then you get the saved information from the custom formatter.One more small remark about your JSON data. Currently you use items like
(if we forget about the
patient_id). It means that you sendidinformation twice: one as the part of the column and second time for the first column of the grid. If you would includekey:truesetting in the definition of the first grid column and addjsonReader: {cell:""}you could make the JSON data in more compact where the row item would be in the array form