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,
开发者_C百科 "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_id
are always the same as the id
. I suppose that there can be different (if patient_id
are equal to id
you can see the information in the custom formatter already). You can implement what you need in at least three ways:
- You add an hidden column (having the property
hidden:true
) which will represent thepatient_id
. You move the information about thepatient_id
in the JSON input inside the"cell"
array. - You place the information about the mapping between
id
andpatient_id
as the part ofuserdata
which you will include in the JSON (see here for more information). - You use
data
parameter of theloadComplete
event handle. Thedata
parameter will contain full JSON data posted from the server. You can get the information which you need from thedata
and 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
{
"cell": [
"637",
"Alice",
"Test",
"01\/01\/1980",
""
],
"id": "637",
}
(if we forget about the patient_id
). It means that you send id
information twice: one as the part of the column and second time for the first column of the grid. If you would include key:true
setting in the definition of the first grid column and add jsonReader: {cell:""}
you could make the JSON data in more compact where the row item would be in the array form
[
"637",
"Alice",
"Test",
"01\/01\/1980",
""
]
Add a hidden column for the extra data.
精彩评论