代码之家  ›  专栏  ›  技术社区  ›  Brij

数组数据在jqgrid中的分页问题

  •  4
  • Brij  · 技术社区  · 14 年前

    我在jqgrid中面临分页问题,数组数据有18条记录,但即使我指定了p,记录也不会显示在页面中激动:真的,寻呼机:jQuery('第1页')。你能帮我实现分页而不是滚动吗。

    <script type="text/javascript">
     jQuery("#list4").jqGrid({
     datatype: "clientSide",
     height: 200,
        colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
        colModel:[
        {name:'id',index:'id', width:60, sorttype:"int"},
        {name:'invdate',index:'invdate', width:90, sorttype:"date"},
        {name:'name',index:'name', width:100},
        {name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
        {name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
        {name:'total',index:'total', width:80,align:"right",sorttype:"float"},
        {name:'note',index:'note', width:150, sortable:false}
        ],
        multiselect: true,
     pagination:true,
      pager:jQuery('#pager1'), 
     rowNum: 10,
     rowList: [5, 10, 20, 50],
     sortname: 'id',   
     sortorder: 'asc',
     viewrecords: true,
     page: 1,
     loadonce: true,  
     totalpages: 2,   
     totalrecords:18,     
     showpage:true,   
     imgpath: "/themes/default/images",         
     caption: "Manipulating Array Data"
     });
     var mydata = [
     {id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
     {id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
     {id:"3",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
     {id:"4",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
     {id:"5",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
     {id:"6",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
     {id:"7",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
     {id:"8",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
     {id:"9",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
     {id:"10",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
     {id:"11",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
     {id:"12",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
     {id:"13",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
     {id:"14",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
     {id:"15",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
     {id:"16",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
     {id:"17",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
     {id:"18",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
    
     ];
     for(var i=0;i<=mydata.length;i++)   
     jQuery("#list4").addRowData(i+1,mydata[i]);
    
    2 回复  |  直到 14 年前
        1
  •  10
  •   Chepech    12 年前

    你的主要问题是你应该重置 rowNum 在添加大量行之后。线路

    jQuery("#list4").setGridParam({ rowNum: 10 }).trigger("reloadGrid");
    

    jQuery("#list4").jqGrid('navGrid','#pager1',{edit:false,add:false,del:false});
    

    直接在jqGrid的定义之后。这样,您不仅可以进行数据分页,还可以进行数据过滤(搜索)和刷新(重置过滤器)。

    还有一些小评论:

    • mydata 应删除“,”在“]”之前的数组。
    • 在for循环中,您应该使用 i<mydata.length 而不是 i<=mydata.length .
    • 您应该从jqGrid的定义中删除以下不存在的参数(如 pagination loadonce: true ): , page , loadonce , totalpages , totalrecords showpage , imgpath .

    data: myData 参数,或从 addRowData 中的方法 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#array_data

        2
  •  1
  •   Chandima.Jayawickrema    12 年前

    添加jQuery(“#list4”).setGridParam({rowNum:10}).trigger(“reloadGrid”);

    但如果 格式化程序 属性设置为rowObject值未定义的位置。(如果使用)

    例如

    function getFormattedFileName(cellvalue, options, rowObject) {
    
            if(!rowObject.fileName) {// this is due to ...trigger("reloadGrid");
                return cellvalue; // the value is already formatted, let's just return it
            }
     return rowObject.fileName.trim();
    }