2014-10-16 65 views
0

當我使用「loadonce」設置爲「true」時,我的問題是搜索或過濾工程,但分頁不起作用。如果我將loadonce更改爲false,不工作,但分頁工作。當使用loadonce時,Jqgrid無法實現分頁:true

如何確保在分頁期間將數據類型設置爲json。

$grid = $("#list"), 

    numberTemplate = { 
     formatter: 'number', 
     align: 'right', 
     sorttype: 'number', 
     editrules: { 
      number: true, 
      required: true 
     }, 

     searchoptions: { 
      sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'] 
     } 
    }; 
var myDelOptions = { 

    onclickSubmit: function (rp_ge, rowid) { 
     // we can use onclickSubmit function as "onclick" on "Delete" button 
     // alert("The row with rowid="+rowid+" will be deleted"); 

     // delete row 
     grid.delRowData(rowid); 
     $("#delmod" + grid[0].id).hide(); 

     if (grid[0].p.lastpage > 1) { 
      // reload grid to make the row from the next page visable. 
      // TODO: deleting the last row from the last page which number is higher as 1 
      grid.trigger("reloadGrid", [{ 
       page: grid[0].p.page 
      }]); 
     } 

     return true; 
    }, 
    processing: true 
}; 

$.extend($.jgrid.inlineEdit, { 
    keys: true 
}); 
$grid.jqGrid({ 
    url: $('#contextPath').val() +"/globalcodes/getList?masterCodeSysid="+$('#Sysid').val(),   
    datatype: 'json', 
    colNames: ['Sequence', 'Detail Code', 'Code Description', 'Status', 'Cross Referrences', '', ''], 
    colModel: [ { 
        name: 'seqNumber', 
        width: 50, 
        editable: false, 
        search:true 


       }, { 
        name: 'dtlCode', 
        width: 50, 
        editable: true, 
        searchoptions:{sopt:['cn','eq','ne']} 
       }, { 
        name: 'codeDesc', 
        width: 200 , 
        searchoptions:{sopt:['cn','eq','ne']} 
       }, { 
        name: 'statusFlag', 
        width: 150, 
        edittype:"select", 
        formatter : 'select', 
        editoptions:{value:"Y:Active;N:Inactive"}, 
        searchoptions:{sopt:['cn','eq','ne']} 
       }, { 
        name: 'crossReferrenced', 
        width: 100, 
        editable: false, 
        searchoptions:{sopt:['cn','eq','ne']} 
       },{ 
        name: 'act', 
        index: 'act', 
        width: 55, 
        align: 'center', 
        search: false, 
        sortable: false, 
        formatter: 'actions', 
        searchoptions:{sopt:['cn','eq','ne']} , 
        editable: false, 
        formatoptions: { 
         keys: true, // we want use [Enter] key to save the row and [Esc] to cancel editing. 
         onEdit: function (rowid) { 
          $('#add_detail_code').attr('disabled','disabled').addClass("btnDisabled").removeClass("btnNormalInactive"); 
         }, 
         onSuccess: function (jqXHR) { 
          $grid.setGridParam({ rowNum: 10 }).trigger('reloadGrid'); 
         }, 
         afterSave: function (rowid) {        
          $('#add_detail_code').removeAttr('disabled').addClass("btnNormalInactive").removeClass("btnDisabled"); 
         }, 
         afterRestore: function (rowid) {         
          $('#add_detail_code').removeAttr('disabled').addClass("btnNormalInactive").removeClass("btnDisabled"); 
         }, 
         delOptions: myDelOptions 
        } 
    },{ 
     name: 'dtlCodeSysid', 
     hidden: true 
    }], 

    cmTemplate: { 
     editable: true 
    }, 
    jsonReader: {id:'dtlCodeSysid', 
     }, 
    rowList: [5, 10, 20], 
    pager: '#detailCodePager', 
    gridview: true,    
    ignoreCase: true, 
    rowNum:10, 
    rownumbers: false, 
    sortname: 'col1', 
    loadonce:true, 
    viewrecords: true, 
    sortorder: 'asc', 
    height: '100%', 
    deepempty: true, 
    editurl: $('#contextPath').val() +"/globalcodes/saveMasterCodeDetails?masterCodeSysId="+$('#masterCodeSysid').val(),  
    //caption: 'Usage of inlineNav for inline editing', 
}); 
$grid.jqGrid('filterToolbar', { 
    searchOperators: true 
}); 

$grid.jqGrid('navGrid', '#detailCodePager', { 
    add: false, 
    edit: false, 
    del: false, 
    search:false, 
    refresh:true 
}); 

回答

1

您沒有發佈任何您使用的代碼,所以我嘗試猜測。可能您在服務器端實施了分頁,並且在使用loadonce: true選項的情況下僅返回一頁數據。在服務器端正確使用loadonce: true將返回所有數據,數據需要根據jqGrid發送的排序參數正確排序。順便說一下,從服務器返回的數據的格式可以只是項目的數組,而不是在{ "total": "xxx", "page": "yyy", "records": "zzz", "rows" : [...]}中包裝結果。在使用loadonce: true選項的情況下,將根據數組返回數據的大小忽略並計算來自total,pagerecords的數據。

+0

對不起,先生,我應該發佈代碼以獲得更好的解釋。我現在有了。我試過的是我刪除了rowNum:10,並試圖在代碼的最後一行設置「jQuery(」#list「)。setGridParam({rowNum:10})。trigger(」reloadGrid「)」 – user2375298 2014-10-16 14:50:50

+0

@ user2375298:問題是*不在客戶端* - 我想它在服務器端。如果你想使用'loadonce:true'選項,那麼服務器必須在頁面大小('rowNum'選項)上獨立返回**所有數據**。如果你的服務器代碼只返回數據頁面,那麼'loadonce:true'的實現就是錯誤的。 – Oleg 2014-10-16 14:53:15

+0

但如果我刪除負載一次爲真,那麼尋呼機顯示確切數量的數據,但是當我設置loadOnce:true時,尋呼機顯示rowNum值。不過,我已將rowNum 10放在解決我的分頁問題的最後一行。 – user2375298 2014-10-16 14:58:48

相關問題