Pagination problem in jqgrid with array data.

Pagination problem in jqgrid with array data.

Hi All,

I am facing problem with pagination in jqgrid with array data having 18 records, but the records are not displaying in pages even I specified pagination:true,pager:jQuery('#pager1'). Can you please help me to implement pagination instead of scrolling.

Please find the code below : 

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>jqGrid Example</title>

  6. <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
  7. <script src="js/jquery-ui-1.8.custom.min.js" type="text/javascript" ></script>
  8. <script src="js/grid.locale-en.js" type="text/javascript"></script>
  9. <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
  10. <script src="js/grid.custom.js" type="text/javascript"></script>
  11. <link href="css/jquery-ui-1.8.custom.css" rel="Stylesheet" type="text/css" />
  12. <link type="text/css" href="themes/default/style.css" rel="Stylesheet"/>      
  13. <link rel="stylesheet" type="text/css" media="screen" href="themes/ui.jqgrid.css" />
  14. <link rel="stylesheet" type="text/css" media="screen" href="themes/ui.multiselect.css" />    
  15. <script src="js/grid.custom.js" type="text/javascript"></script>   
  16.    
  17.    
  18. </head>      

  19. <body>


  20. <div align="center">
  21. <div id="search"></div>
  22. <table id="list4" class="scroll" cellpadding="0" cellspacing="0"></table>
  23. <div id="pager1" class="scroll" style="text-align:center;"></div>   
  24. <input type="button" value="Delete Row" onclick="deleteRow();" /><br />
  25. <input type="button" value="Get Row IDs" onclick="getRowIDs();" /><br />
  26. <input type="button" value="Move up" onclick="move('up');" /><br />
  27. <input type="button" value="Move down" onclick="move('down');" /><br />
  28. <input type="button" value="Get Current Row" onclick="getCurrentRow();" />
  29. </div>   
  30. <script type="text/javascript">
  31. jQuery("#list4").jqGrid({
  32. datatype: "clientSide",
  33. height: 200,
  34.    colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
  35.    colModel:[
  36.    {name:'id',index:'id', width:60, sorttype:"int"},
  37.    {name:'invdate',index:'invdate', width:90, sorttype:"date"},
  38.    {name:'name',index:'name', width:100},
  39.    {name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
  40.    {name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
  41.    {name:'total',index:'total', width:80,align:"right",sorttype:"float"},
  42.    {name:'note',index:'note', width:150, sortable:false}
  43.    ],
  44.    multiselect: true,
  45. pagination:true,
  46.  pager:jQuery('#pager1'), 
  47. rowNum: 10,
  48. rowList: [5, 10, 20, 50],
  49. sortname: 'id',   
  50. sortorder: 'asc',
  51. viewrecords: true,
  52. page: 1,
  53. loadonce: true,  
  54. totalpages: 2,   
  55. totalrecords:18,     
  56. showpage:true,   
  57. imgpath: "/themes/default/images",         
  58. caption: "Manipulating Array Data"
  59. });
  60. var mydata = [
  61. {id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
  62. {id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
  63. {id:"3",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
  64. {id:"4",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
  65. {id:"5",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
  66. {id:"6",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
  67. {id:"7",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
  68. {id:"8",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
  69. {id:"9",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
  70. {id:"10",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
  71. {id:"11",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
  72. {id:"12",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
  73. {id:"13",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
  74. {id:"14",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
  75. {id:"15",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
  76. {id:"16",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
  77. {id:"17",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
  78. {id:"18",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
  79. ];
  80. for(var i=0;i<=mydata.length;i++)   
  81. jQuery("#list4").jqGrid('addRowData',i+1,mydata[i]);

  82.  function deleteRow(){
  83.  var tableData = new Array();
  84.  var ids = '';
  85.  $table.delRowData($table.getGridParam('selrow'));
  86.  ids = $table.getDataIDs();
  87.  for(var i = 0; i < ids.length; i++){
  88.  
  89.  tableData[i] = $table.getRowData(ids[i]);
  90.  tableData[i].id = i + 1;
  91.  }
  92.  $table.clearGridData(false);
  93.  for(i = 0; i < tableData.length; i++){
  94.  $table.addRowData(i + 1, tableData[i]);
  95.  }
  96.  }
  97.  function move(direction){
  98.  if($table.getGridParam('selrow')){
  99.  var ids = $table.getDataIDs();
  100.  var temp = 0;
  101.  var currRow = ids[ $table.getGridParam('selrow') - 1 ];
  102.  if(direction === 'up' && currRow > 1){
  103.  var r1 = $table.getRowData(currRow-1);
  104.  var r2 = $table.getRowData(currRow);
  105.  $table.delRowData(currRow-1);
  106.  $table.delRowData(currRow);
  107.  temp = r1.id;
  108.  r1.id = r2.id;
  109.  r2.id = temp;
  110.  $table.addRowData(r2.id, r2);
  111.  $table.addRowData(r1.id, r1);
  112.  }
  113.  if(direction === 'down' && currRow < (ids.length)){
  114.  var r1 = $table.getRowData(currRow);
  115.  var r2 = $table.getRowData(parseInt(currRow)+1);
  116.  $table.delRowData(currRow);
  117.  $table.delRowData(parseInt(currRow)+1);
  118.  temp = r1.id;
  119.  r1.id = r2.id;
  120.  r2.id = temp;
  121.  $table.addRowData(r1.id, r1);
  122.  $table.addRowData(r2.id, r2);
  123.  }
  124.  // Sort the table   
  125.  $table.setGridParam({sortname:'id'}).trigger('reloadGrid');
  126.  }
  127.  }
  128.  function dumpObject(obj){
  129.  var dataString = '';
  130.  for(var i in obj){
  131.  dataString += i + ': ' + obj[i] + '\n';
  132.  }
  133.  alert(dataString);
  134.  }
  135.  function getRowIDs(){
  136.  var ids = $table.getDataIDs();
  137.  var dataString = '';
  138.  for(var i = 0; i < ids.length; i++){
  139.  dataString += 'postion: ' + i + ' ' + ids[i] + '\n';
  140.  }
  141.  alert(dataString);
  142.  }
  143.  function getCurrentRow(){
  144.  var dataString = '';
  145.  var ids = $table.getDataIDs();
  146.  dataString += 'Selected Row: ' + $table.getGridParam('selrow') + '\nRow ID: ' + ids[$table.getGridParam('selrow') - 1];
  147.  alert(dataString);
  148.  }
  149. </script>

  150. </body>
  151. </html>