The following json and jqgrid options give me no data in my grid.
var grid = jQuery("#grid")[0];
grid.addJSONData({ // the json
total: 1,
page: 1,
records: 10,
items: [
{ ProductID: '1', Name: 'Coke' },
{ ProductID: '2', Name: 'Pepsi' },
{ ProductID: '3', Name: 'L&P' },
{ ProductID: '4', Name: 'A&B' },
{ ProductID: '5', Name: 'All Star' },
{ ProductID: '6', Name: 'Wai' },
{ ProductID: '7', Name: 'cd' },
{ ProductID: '8', Name: 'LV' },
{ ProductID: '9', Name: 'DD' },
{ ProductID: '10', Name: 'aW' }
]
});
// jqGrid options
{
...
colNames: ['ProductID', 'Name'],
colModel: [{ name: 'ProductID', Label: 'Id' },
{ name: 'Name', Label: 'Name'}],
jsonReader: {
root: 'items',
cell: ''
},
...
}
Your data has no
idproperties. It seems thatProductIDplay the role of id of your data. So you should use additionalkey:trueoption in the definition of theProductIDcolumn or include ‘id:ProductID’ in thejsonReader.Moreover the
Labelproperty should be written in low case:label. It replace the value from the column headercolNames. If you uselabelproperty for all columns you not need more definecolNamesarray.If you want to fill the jqGrid with the local data the most effective way is to use addRowData function. In the case you should use
localReaderinstead ofjsonReader. It can be used to add not only a row, but an array of row data. In the case of arrays as data the first parameter should be the name of id property. So your code could look like following:If all this will not help, you should include in your question the whole code which can be used to reproduce your problem.