2011-06-24 32 views
0
$(document).ready(function(){ 
    $("#gridList").jqGrid({ 
     url:'server.json', 
     mtype: 'GET', 
     datatype: "json", 
     colNames:['NO','DATA', 'CLIENT', 'AMOUNT','TEX','TOTAL','NOTE'], 
     colModel:[ 
      {name:'id',index:'id', width:100,align:"center",key:true,sorttype:'int'}, 
      {name:'invdate',index:'invdate', width:120,editable:true,sorttype:"date",formatter:'date', formatoptions:{srcformat:"Y-m-d",newformat:"d-M-Y"}}, 
      {name:'name',index:'name', width:100,editable:true,editoptions:{size:"20",maxlength:"30"}}, 
      {name:'amount',index:'amount', width:100, align:"right",editable:true,editable:true,editrules:{number:true,minValue:100,maxValue:350},formatter:'currency',formatoptions:{thousandsSeparator:","}}, 
      {name:'tax',index:'tax', width:100, align:"right",editable:true,edittype:"select",editoptions:{value:"FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX"}}, 
      {name:'total',index:'total', width:100,align:"right",editable:true,edittype:"checkbox",editoptions: {value:"Yes:No"}}, 
      {name:'note',index:'note', width:150, sortable:false,editable:true,edittype:"textarea", editoptions:{rows:"1",cols:"20"}} 
     ], 
     rowNum:10, 
     height:278, 
     sortname: 'id', 
     sortorder: "asc", 
     viewrecords: true, 
     multiselect: false, 
     editurl: "server.json", 
     loadonce:false, 
     imgpath: 'style/grid' 
    }); 

    var a = $('#gridList').jqGrid('getGridParam','rowNum'); 

    alert(a);   // *result --> [object Object] 
    alert(a.rowNum); // *result --> undefined 
    alert(parseInt(a)); // *result --> NaN 
} 

有關如何獲取正確值的信息?中的jqGrid的rowNum使用JSON要輸出的值


server.json文件是在同一文件夾

server.json:

{ 
    "page": "1", 
    "total": 15, 
    "records": "13", 
    "rows": [ 
     { 
      "id": "15", 
      "cell": [ 
       "15", 
       "2007-10-06", 
       "Client 1", 
       "200.00", 
       "40.00", 
       "240.00", 
       null 
      ] 
     }, 
     { 
      "id": "14", 
      "cell": [ 
       "14", 
       "2007-10-06", 
       "Client 3", 
       "200.00", 
       "0.00", 
       "200.00", 
       null 
      ] 
     }, 
     { 
      "id": "13", 
      "cell": [ 
       "13", 
       "2007-10-05", 
       "Client 2", 
       "120.00", 
       "12.00", 
       "134.00", 
       null 
      ] 
     }, 
     { 
      "id": "12", 
      "cell": [ 
       "12", 
       "2007-10-05", 
       "Client 1", 
       "50.00", 
       "10.00", 
       "60.00", 
       null 
      ] 
     }, 
     { 
      "id": "11", 
      "cell": [ 
       "11", 
       "2007-10-05", 
       "Client 3", 
       "100.00", 
       "0.00", 
       "100.00", 
       "no tax" 
      ] 
     }, 
     { 
      "id": "10", 
      "cell": [ 
       "10", 
       "2007-10-06", 
       "Client 3", 
       "1000.00", 
       "0.00", 
       "1000.00", 
       null 
      ] 
     }, 
     { 
      "id": "9", 
      "cell": [ 
       "9", 
       "2007-10-06", 
       "Client 2", 
       "700.00", 
       "140.00", 
       "840.00", 
       null 
      ] 
     }, 
     { 
      "id": "8", 
      "cell": [ 
       "11", 
       "2007-10-06", 
       "Client 1", 
       "600.00", 
       "120.00", 
       "720.00", 
       null 
      ] 
     }, 
     { 
      "id": "7", 
      "cell": [ 
       "7", 
       "2007-10-06", 
       "Client 2", 
       "100.00", 
       "20.00", 
       "120.00", 
       null 
      ] 
     }, 
     { 
      "id": "6", 
      "cell": [ 
       "6", 
       "2007-10-06", 
       "Client 1", 
       "200.00", 
       "40.00", 
       "240.00", 
       null 
      ] 
     }, 
     { 
      "id": "5", 
      "cell": [ 
       "5", 
       "2007-10-06", 
       "Client 3", 
       "200.00", 
       "0.00", 
       "200.00", 
       null 
      ] 
     }, 
     { 
      "id": "4", 
      "cell": [ 
       "4", 
       "2007-10-05", 
       "Client 2", 
       "120.00", 
       "12.00", 
       "134.00", 
       null 
      ] 
     }, 
     { 
      "id": "3", 
      "cell": [ 
       "3", 
       "2007-10-05", 
       "Client 1", 
       "50.00", 
       "10.00", 
       "60.00", 
       null 
      ] 
     }, 
     { 
      "id": "2", 
      "cell": [ 
       "2", 
       "2007-10-05", 
       "Client 3", 
       "100.00", 
       "0.00", 
       "100.00", 
       "no tax" 
      ] 
     }, 
     { 
      "id": "1", 
      "cell": [ 
       "1", 
       "2007-10-04", 
       "Client 3", 
       "150.00", 
       "0.00", 
       "150.00", 
       "no tax" 
      ] 
     } 
    ] 
} 
+0

我無法重現您的問題。在我的測試中,alert(a);'應該顯示「10」。你可以發佈URL的問題,所以我可以調試它? – Oleg

+0

我很警覺('a')沒有超出價值。 – lee

回答

0

你怎麼能在the demo看到的一切工作正確alert(a)alert(parseInt(a))顯示 「10」。您可以將我的演示代碼與青年代表進行比較,以找出差異。

+0

對不起,只對那些人很重要 – lee