jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Goto Page in JQGrid
Tagged: grid pager, grid paging, jquery grid
This topic contains 2 replies, has 2 voices, and was last updated by Syai 11 years, 12 months ago.
-
AuthorGoto Page in JQGrid Posts
-
Hi,
I’m trying to go to 1st page of the grid using “gotopage” functionality. But couldn’t succeed. It didn’t work when I give the page number to which the page to be navigated. So I gave negative value as parameter, it worked fine when I’m in 2nd page of the grid but not working in other pages(>2). It is glad if anyone help regarding this.
Below is the piece of the code I’ve used
Here I’m trying to go to page 1 of the grid so I used the syntax as
$(“#jqxgrid”).jqxGrid(‘gotopage’,1));
But it didn’t work.
So I’ve tried like
var paginginformation = $(‘#jqxgrid’).jqxGrid(‘getpaginginformation’);
var PageNumber = paginginformation.pagenum;
$(“#jqxgrid”).jqxGrid(‘gotopage’,-1*(PageNumber));
The above code worked when I’m in the 2nd page and didn’t work in other pages.
Thanks & Regards,
Syai
Hi Syai,
Here’s a sample code with “gotopage” method. In addition, note that the page’s index is zero-based so to go to the first page, you should call the method with 0 as param.
<!DOCTYPE html><html lang="en"><head> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.8.2.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.sort.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.pager.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.edit.js"></script> <script type="text/javascript" src="../../scripts/gettheme.js"></script> <script type="text/javascript"> $(document).ready(function () { var theme = getDemoTheme(); var url = "../sampledata/products.xml"; // prepare the data var source = { datatype: "xml", datafields: [ { name: 'ProductName', type: 'string' }, { name: 'QuantityPerUnit', type: 'int' }, { name: 'UnitPrice', type: 'float' }, { name: 'UnitsInStock', type: 'float' }, { name: 'Discontinued', type: 'bool' } ], root: "Products", record: "Product", id: 'ProductID', url: url }; var cellsrenderer = function (row, columnfield, value, defaulthtml, columnproperties) { if (value < 20) { return '<span style="margin: 4px; float: ' + columnproperties.cellsalign + '; color: #ff0000;">' + value + '</span>'; } else { return '<span style="margin: 4px; float: ' + columnproperties.cellsalign + '; color: #008000;">' + value + '</span>'; } } var dataAdapter = new $.jqx.dataAdapter(source, { downloadComplete: function (data, status, xhr) { }, loadComplete: function (data) { }, loadError: function (xhr, status, error) { } }); // initialize jqxGrid $("#jqxgrid").jqxGrid( { width: 670, source: dataAdapter, theme: theme, pageable: true, autoheight: true, sortable: true, altrows: true, enabletooltips: true, editable: true, selectionmode: 'multiplecellsadvanced', columns: [ { text: 'Product Name', datafield: 'ProductName', width: 250 }, { text: 'Quantity per Unit', datafield: 'QuantityPerUnit', cellsalign: 'right', align: 'right', width: 120 }, { text: 'Unit Price', datafield: 'UnitPrice', align: 'right', cellsalign: 'right', cellsformat: 'c2', width: 100 }, { text: 'Units In Stock', datafield: 'UnitsInStock', cellsalign: 'right', cellsrenderer: cellsrenderer, width: 100 }, { text: 'Discontinued', columntype: 'checkbox', datafield: 'Discontinued' }, ] }); $("#btn").click(function () { $("#jqxgrid").jqxGrid('gotopage', 0); }); }); </script></head><body class='default'> <div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;"> <div id="jqxgrid"> </div> <input id="btn" type="Button" value="Go to 1st Page" /> </div></body></html>
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
Thanks for the reply. It is working like charm when we pass “0” as param.
Regards,
Syai -
AuthorPosts
You must be logged in to reply to this topic.