I have a grid using jqgrid
. I need to store the some data returned by the url:
, in a local variable so that I can display it in the subgrid
. For this I add that column as a hidden column in the main grid, which is of the format in json
:
"Details":[{"Name":"ttt", "Quantity":"12"}] .
Then in the loadcomplete: function I save the value to a variable using
var griddata = $("#grid').getCol('Details', false);
Now when I access griddata[0]
, I get a object
Object. I tried to parse it to get the values correctly, but to no avail. I tried:
griddata[0].Details.Name
or
griddata[0].Details.0.Name
or
griddata[0].Name,
but all failed. I guess I am missing the format if the data returned by the getcol()
function.I looked up the documentation on the method and it says that it returns just the values when we specify false, but could not get any examples.
If there are any examples or if there are any pointer to the solution, it will be greatly appreciated.
If you check the type of
griddata[0]
(for example withtypeof
operator) you will see that it has type ofstring
- this is because the value you are getting is the result oftoString()
on the object you have passed. The reason for that is the way in which jqGrid is treating values.If you want to store JSON as the value, you need to stringify it entirely:
Now you can deserialize those string values into objects like this:
After that you can access the objects in the way you want:
As an alternative you can split your object into two columns, so the values can be accessed directly with
getCol
.