Reputation: 704
I have a JSON response from server which I am trying to bind to JQgrid. However, the response is a JSON string has "dot" as a part of the object name. I am unable to get the JQGrid work with the "dot"
Here is the sample fiddle for the problem I am facing http://jsfiddle.net/sharathchandramg/rpdfrb0L/2/
$("#grid").jqGrid({
data: data,
datatype: "local",
height: 250,
colNames: ['Name', 'Cluster', 'Location'],
colModel: [{
name: 'name',
width: 120
}, {
name: 'metrics.cluster.first.value',
width: 60,
jsonmap: function (obj) {
return obj.metrics['cluster.first'].value
}
}, {
name: 'metrics.location-latitude.value',
width: 60
}, ],
caption: "Example"
});
As shown the fiddle, I am not able to bind the property "cluster.first" even while using jsonmap. Whereas if the property name is "location-latitude" the grid works fine.
Let me know what I am doing wrong.
Upvotes: 0
Views: 1242
Reputation: 221997
The reason is very easy. The property jsonmap
will be ignored in case of usage datatype: "local"
in jqGrid 4.6. I changed the behavior in free jqGrid (see the wiki). So one possible solution will be to use free jqGrid 4.8 or higher instead of jqGrid 4.6.
One more simple way to solve the problem will be usage of datatype: "jsonstring"
. You can verified
$("#grid").jqGrid({
datastr: data,
datatype: "jsonstring",
height: "auto",
colNames: ['Name', 'Cluster', 'Location'],
colModel: [{
name: 'name',
width: 120
}, {
name: 'metrics_cluster_first_value',
width: 60,
jsonmap: function (obj) {
return obj.metrics['cluster.first'].value
}
}, {
name: 'metrics_location_latitude_value',
jsonmap: 'metrics.location-latitude.value',
width: 60
}],
caption: "Example"
});
See http://jsfiddle.net/OlegKi/rpdfrb0L/5/. You can see additionally that I changed name
property of all colModel
items to have no dots inside. I recommend to follow the rule always.
Upvotes: 2