Storing a json array in a hidden column of a jqgrid
Hidden column is just a column which has CSS style display: none
. You can't place object on HTML page inside of <td>...</td>
. So the object will be converted to string automatically by calling toString
method.
What you really need is saving of objects (array for example) somewhere. When the user selects later a row of grid the callback onSelectRow
are called. The callback has rowid as a parameter. So the best will be to save your custom information as dictionary (object) by rowids.
One of the option will be sending additional information not inside of rows
part of the server response, but inside of userdata
instead. For example you try to send currently the data in the following format
{ "page": 1 "total": 7 "records": 123 "rows": [ {"id": 10, "cell": ["cell11", "cell12", "cell13", [1, 2, 3]]} {"id": 20, "cell": ["cell11", "cell12", "cell13", [4, 5, 6]]}, ... {"id": 90, "cell": ["cell11", "cell12", "cell13", [9, 8, 7]]} ]}
You can modify the server response to
{ "page": 1 "total": 7 "records": 123 "rows": [ {"id": 10, "cell": ["cell11", "cell12", "cell13", [1, 2, 3]]} {"id": 20, "cell": ["cell11", "cell12", "cell13", [4, 5, 6]]}, ... {"id": 90, "cell": ["cell11", "cell12", "cell13", [9, 8, 7]]} ], "userdata": { "10": [1, 2, 3], "20": [4, 5, 6], ... "90": [9, 8, 7] }}
In the case the userdata
part will be automatically saved by jqGrid inside of internal parameter userData
(be carefull with usage of case in "userdata" in JSON data and "userData"
as parameter).
Now you will be able to get your custom data inside any callback in the following way:
onSelectRow: function (rowid) { var custom = $(this).jqGrid("getGridParam", "userData"); // custom[rowid] is the data from userdata like [4, 5, 6]}
If you can't modify the server response you can move your custom data to userdata
part inside of beforeProcessing
callback. See the answer for an example of such code.