2011-09-08 60 views
0

當我打電話getrowdata()我收到此錯誤$ tpcolModel [i]於grid.base.js未定義

jQuery(jqgrid).jqGrid({ 
      url: url, 
      datatype: 'json', 
      mtype: 'GET', 
      colNames: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'], 
      colModel: [{ name: 'A', index: 'A', width: 50, align: 'right', sortable: true, resizable: false }, 
      { name: 'B', index: 'B', width: 50, align: 'right', sortable: true, sorttype: 'int', title: false, resizable: false }, 
      { name: 'C', index: 'C', width: 50, align: 'right', sortable: true, sorttype: 'int', resizable: false }, 
      { name: 'D', index: 'D', width: 40, align: 'right', sortable: true, sorttype: 'int', title: false, resizable: false }, 
      { name: 'E', index: 'E', width: 75, align: 'right', sortable: true, sorttype: 'float', resizable: false }, 
      { name: 'F', index: 'F', width: 75, sortable: true, datefmt: ' M d, y H:i:s', resizable: false }, 
      { name: 'G', index: 'G', width: 75, sortable: true, datefmt: ' M d, y H:i:s', resizable: false }, 
      { name: 'H', index: 'H', width: 500, sortable: true, sorttype: 'text', resizable: false }, 
      { name: 'I', index: 'I', width: 300, sortable: true, sorttype: 'text', resizable: false}], 
jsonReader: { 
       root: "A", 
       page: "page", 
       total: "total", 
       records: "records", 
       repeatitems: false 
      } 
}); 

jsondata格式

{ "total":"4", 
    "page":"1", 
    "records":"35", 
    "A":[{ 
      "A":"01.000", 
      "B":"01.000", 
      "C":"01.000", 
      "D":"1", 
      "E":"1.075", 
      "F":" 19:17:09", 
      "G":" 11 19:17:09", 
      "H":"dfsd", 
      "I":""}]} 

收到錯誤:$t.p.colModel[i] is undefined in grid.base.js(line 2470)

回答

0

首先,你的JSON數據應該開始 「{」("{"total":"4",...")。 其次,因爲你用「A」屬性作爲行的數組名("A":[),你應該使用以下jsonReader

jsonReader: { 
    root: "A", 
    repeatitems: false 
} 
+0

這個問題是json響應中有一些html字符,Jqgrid無法正確處理這些字符。現在我正在對字符進行html化,並且它工作正常。 – Sandy

+1

@Sandy:JSON響應可以包含*任何UNICODE字符*。 **只有兩個字符''''和'\\'必須轉義**(見[這裏](http://www.json.org/)),並且可能會有更多字符*被轉義。 JSON數據[here](http://jsonlint.com/)。在我發佈我的答案之前,我對[此演示]進行了驗證(http://www.ok-soft-gmbh.com/jqGrid/Sandy。 htm),它使用你原來的*發佈的JSON數據,所以如果你仍然有任何問題,原因應該在其他地方 – Oleg

+0

感謝您的回覆。問題出在我的代碼中。它是固定的 – Sandy

2

我使用的jqGrid 3.6.2同樣的問題,同時呼籲$("#myGrid").delRowData("myRowId"); 原因是在運行時添加的一個新的單元格,其中包含一個html表格<table><tr><td>cell value</td> ...。看來,方法$("#myGrid").delRowData通過包含內部表的方法來錯誤地計算jqGrid tds。

相關問題