2013-06-21 389 views
2
  1. 下面的代碼是我jqGrid的代碼,我使用JsonReader綁定在網格數據。另外找到下面張貼的圖像。

2.我的服務響應是JSON,所以我使用JSON Reader,如果我改成「localReader」,數據沒有綁定。我jqGrid的尋呼機顯示爲0 1,如果在沒有jqGrid的數據

This is my JQgrid pager, even though, if there is no data, the pager shows 1 of 0.

jQuery(document).ready(function() { 
     $("#datagrid").jqGrid({ 
      url: service url, 
      ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, 
      type: "GET", 
      datatype: "json", 
      colNames:['Id','MID','Status','VendorID','VendorName','InvoiceNo','DocDate','Amount','DocNo','Type','DueDate','ClDoc','Text','UserName','Currency','ConCode','Region','Stat','Process','Comb','Comments'], 
      colModel:[ 
    {name:'id',index:'id', width:50,sortable:true}, 
    {name:'mid',index:'mid', width:50, sortable:true}, 
    {name:'status',index:'status', width:70, sortable:true}, 
    {name:'vendorid',index:'vendorid', width:90, sortable:false,align:"left"}, 
    {name:'vendorname',index:'vendorname', width:170, sortable:false,align:"left"}, 
    {name:'invoiceno',index:'invoiceno', width:130, sortable:false,align:"left"}, 
    {name:'docdate',index:'docdate', width:100, sortable:false}, 
    {name:'amount',index:'amount', width:80, sortable:false,align:"Right"}, 
    {name:'docno',index:'docno', width:100, sortable:false}, 
    {name:'typee',index:'typee', width:50, sortable:false}, 
    {name:'duedate',index:'duedate', width:100, sortable:false}, 
    {name:'cldoc',index:'cldoc', width:80, sortable:false}, 
    {name:'text',index:'texxt', width:70, sortable:false}, 
    {name:'username',index:'username', width:100, sortable:false}, 
    {name:'currency',index:'currency', width:80, sortable:false}, 
    {name:'concode',index:'concode', width:80, sortable:false}, 
    {name:'region',index:'region', width:70, sortable:false}, 
    {name:'stat',index:'stat', width:60, sortable:false}, 
    {name:'process',index:'process', width:60, sortable:false}, 
    {name:'combination',index:'combination', width:60, sortable:true}, 
    {name:'comments',index:'comments', width:150, height:20, edittype:'textarea', sortable:false, editable: true, 
      editoptions: {disabled: false, size:50, resizable:true}} 
    ], 

    jsonReader: { 
     repeatitems: false,  // To Bind the Data in Grid. 
     id: "id", 
     root: function (obj) { return obj; },  // To Bind the Data in Grid. 
     page: function() { return 1; }, 
     total: function() { return 1; }, 
     records: function (obj) { return obj.length; }, 
     subgrid: { 
      root: "rows", 
      cell: "cell", 
      repeatitems: false,      // To Bind the Data in SubGrid. 
      id: "id", 
      root: function (obj) { return obj; }  // To Bind the Data in SubGrid. 
      } 
    }, 

      rowNum:20, 
      rowList:[20,30,40,50], 
      loadonce: true,  // If True, all pages will be loaded, else only 1 page will be displayed. 
      pager: '#navGrid', 
      sortable: true, 
      sortname: 'mid', 
      viewrecords: true, 
      showOn: 'button', 
      multiselect:true, // Enabling Checkbox.  
      sortorder: 'asc', 
      //prmNames: {rows: 'max'}, 
      prmNames: {rows: 'max', search: null}, 
      height: 290, 
      width: 1222, 
      shrinkToFit: false,   // For Horizontal Scrollbar. 
      toolbar: [true,"bottom"],  // For appending Buttons in Toolbar. 
      rownumbers: true    // To display No.of rows. 
     }); 
    }); 
+0

爲什麼ü要使用localReader? –

+1

爲什麼因爲chk這個鏈接,他們給了那個jqgrid尋呼機的替代解決方案,如果你的數據被放置在localReader中的話。 http://stackoverflow.com/questions/16678783/in-the-paging-footer-arent-the-page-1-of-0-suppose-to-say-page-0-of-0 –

回答

3

你引用正確answer這可能對這個問題起到額外的作用。我想你已經使用了最新版本的jqGrid和描述的修復。

我認爲你問題的根源很簡單。您使用的選項jsonReader包含定義爲

page: function() { return 1; } 

page財產這意味着,它的靈魂被顯示的頁碼1即使從服務器響應包含空數組。我認爲你應該代碼更改爲以下

page: function (obj) { return obj.length > 0 ? 1 : 0; } 

page: function (obj) { return obj.length > 0 ? "1" : "0"; } 
+0

謝謝。它正在工作...頁面:function(obj){return obj.length> 0? 1:0; } –

+0

@LakshmanaKumarD:不客氣! – Oleg

+0

也許是較新版本的jQuery,但上述不適合我。我不得不告訴它看行,並返回當前頁面,如果它通過 - >頁面:function(obj){return obj.Rows.length> 0? obj.Page:「0」; } – ASeale