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 :
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <title>jqGrid Example</title>
- <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
- <script src="js/jquery-ui-1.8.custom.min.js" type="text/javascript" ></script>
- <script src="js/grid.locale-en.js" type="text/javascript"></script>
- <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
- <script src="js/grid.custom.js" type="text/javascript"></script>
- <link href="css/jquery-ui-1.8.custom.css" rel="Stylesheet" type="text/css" />
- <link type="text/css" href="themes/default/style.css" rel="Stylesheet"/>
- <link rel="stylesheet" type="text/css" media="screen" href="themes/ui.jqgrid.css" />
- <link rel="stylesheet" type="text/css" media="screen" href="themes/ui.multiselect.css" />
- <script src="js/grid.custom.js" type="text/javascript"></script>
-
-
- </head>
- <body>
- <div align="center">
- <div id="search"></div>
- <table id="list4" class="scroll" cellpadding="0" cellspacing="0"></table>
- <div id="pager1" class="scroll" style="text-align:center;"></div>
- <input type="button" value="Delete Row" onclick="deleteRow();" /><br />
- <input type="button" value="Get Row IDs" onclick="getRowIDs();" /><br />
- <input type="button" value="Move up" onclick="move('up');" /><br />
- <input type="button" value="Move down" onclick="move('down');" /><br />
- <input type="button" value="Get Current Row" onclick="getCurrentRow();" />
- </div>
- <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").jqGrid('addRowData',i+1,mydata[i]);
- function deleteRow(){
- var tableData = new Array();
- var ids = '';
- $table.delRowData($table.getGridParam('selrow'));
- ids = $table.getDataIDs();
- for(var i = 0; i < ids.length; i++){
-
- tableData[i] = $table.getRowData(ids[i]);
- tableData[i].id = i + 1;
- }
- $table.clearGridData(false);
- for(i = 0; i < tableData.length; i++){
- $table.addRowData(i + 1, tableData[i]);
- }
- }
- function move(direction){
- if($table.getGridParam('selrow')){
- var ids = $table.getDataIDs();
- var temp = 0;
- var currRow = ids[ $table.getGridParam('selrow') - 1 ];
- if(direction === 'up' && currRow > 1){
- var r1 = $table.getRowData(currRow-1);
- var r2 = $table.getRowData(currRow);
- $table.delRowData(currRow-1);
- $table.delRowData(currRow);
- temp = r1.id;
- r1.id = r2.id;
- r2.id = temp;
- $table.addRowData(r2.id, r2);
- $table.addRowData(r1.id, r1);
- }
- if(direction === 'down' && currRow < (ids.length)){
- var r1 = $table.getRowData(currRow);
- var r2 = $table.getRowData(parseInt(currRow)+1);
- $table.delRowData(currRow);
- $table.delRowData(parseInt(currRow)+1);
- temp = r1.id;
- r1.id = r2.id;
- r2.id = temp;
- $table.addRowData(r1.id, r1);
- $table.addRowData(r2.id, r2);
- }
- // Sort the table
- $table.setGridParam({sortname:'id'}).trigger('reloadGrid');
- }
- }
- function dumpObject(obj){
- var dataString = '';
- for(var i in obj){
- dataString += i + ': ' + obj[i] + '\n';
- }
- alert(dataString);
- }
- function getRowIDs(){
- var ids = $table.getDataIDs();
- var dataString = '';
- for(var i = 0; i < ids.length; i++){
- dataString += 'postion: ' + i + ' ' + ids[i] + '\n';
- }
- alert(dataString);
- }
- function getCurrentRow(){
- var dataString = '';
- var ids = $table.getDataIDs();
- dataString += 'Selected Row: ' + $table.getGridParam('selrow') + '\nRow ID: ' + ids[$table.getGridParam('selrow') - 1];
- alert(dataString);
- }
- </script>
- </body>
- </html>