2012-11-23 6 views
0

누군가 나를 도와 줄 수 있습니까? json을 사용하여 열과 데이터를 동적으로 렌더링하기 위해 JQGrid를 사용하려고합니다. 열이 나타나고 있지만 행 데이터가 없습니다.JQGrid는 열을 표시하지만 행 데이터는 표시하지 않습니다.

{ 
    "total": 1, 
    "page": 1, 
    "records": 1, 
    "rows": [ 
     { 
      "id": 29291, 
      "cell": [ 
       "Jim", 
       "1", 
       "2" 
      ] 
     } 
    ], 
    "columns": [ 
     "Name", 
     "30/10/2012", 
     "23/10/2012" 
    ], 
    "columnmodel": [ 
     { 
      "name": "Name", 
      "index": "Name", 
      "align": "left", 
      "width": 25 
     }, 
     { 
      "name": "30/10/2012", 
      "index": "30/10/2012", 
      "align": "left", 
      "width": 25 
     }, 
     { 
      "name": "23/10/2012", 
      "index": "23/10/2012", 
      "align": "left", 
      "width": 25 
     } 
    ] 
} 

나는이 사용하고있는 자바 스크립트 : 어떤 도움을 크게 감상 할 수

$.ajax({ 
    type: "GET", 
    url: "ListData?ID=1", 
    datatype: "json", 
    success: function(result){ 
     $("#customgrid").jqGrid({ 
       datatype: "json", 
       colNames: result.columns, 
       colModel: result.columnmodel, 
       data: result.rows, 
       width: 800, 
       pager: "#customgridpager", 
       viewrecords: true, 
       sortable: true, 
       gridview: true, 
     }); 
    }, 
}); 

다음

내가 내 서비스에서 반환 오전 JSON이다.

답변

2

코드에 약간의 변경 만하면됩니다. $.ajax 전화에서 입력 오류를 먼저 변경해야합니다 (datatype에서 dataType으로 변경). 그런 다음 datatype: "json"에서 datatype: "jsonstring"data: result.rows에서 datastr: result으로 변경해야합니다. 내가 당신을 제안 전체 코드는 다음과 같습니다 : 데모의

$.ajax({ 
    type: "GET", 
    url: "NiallGray.json", 
    dataType: "json", 
    success: function (result) { 
     $("#customgrid").jqGrid({ 
      datatype: "jsonstring", 
      colNames: result.columns, 
      colModel: result.columnmodel, 
      datastr: result, 
      width: 800, 
      pager: "#customgridpager", 
      viewrecords: true, 
      sortable: true, 
      gridview: true, 
      rowNum: 10000, 
      height: "auto" 
     }); 
    } 
}); 

수정 된 버전은 here입니다 :

enter image description here

+0

전설! 매우 감사합니다. 좋은 주말 보내세요. –

관련 문제