cem
cem

Reputation: 1655

jqGrid: Uncaught TypeError: Cannot read property 'template' of undefined

I am getting this error on title even everything is seeming fine:

<table id="kpi-grid"></table>
<script>
var kpi_grid = $("#kpi-grid");
$(document).ready(function() {
 $("#kpi-grid").jqGrid({
datatype: 'json'
, url: 'someurl' 
, colNames: ["x1", "x2"]
, colModel: [
    {name: "x1", width: 50 } 
    , {name: "x2", width: 140 } 
]
, ignoreCase: true 
, loadonce: true 
, contentType: "application/json" 
, jsonReader: { root: "rows", id: "id" } 
, gridView: true // <== Problem was here, should be gridview
, rownumbers: true 
, viewrecords: true 
, height: '100%' 
});
});
</script>

The place which throws error on jqGrid source is such:

for (i=0; i<ts.p.colModel.length;i++) {
    ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, ts.p.colModel[i].template || {}, ts.p.colModel[i]);
    if (ts.p.keyIndex === false && ts.p.colModel[i].key===true) {
        ts.p.keyIndex = i;
    }
}

This structure works on my other grids on project, but this one doesn't function.

Upvotes: 2

Views: 1961

Answers (1)

Jay
Jay

Reputation: 61

Change your from jsonReader: { root: "rows", id: "id" } to { root: "rows", id: "id",repeatitems: false }. The repeatitems "element tells jqGrid that the information for the data in the row is repeatable - i.e. the elements have the same tag cell described in cell element. Setting this option to false instructs jqGrid to search elements in the json data by name."

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data

Upvotes: 1

Related Questions