jQuery UI Widgets › Forums › Grid › Adding a button in pager tab
Tagged: Button, custom, DropDownList, first, grid, jqxButton, jqxDropDownList, jqxgrid, last, option, page, pager, pagerrenderer, pagesize, size
This topic contains 13 replies, has 3 voices, and was last updated by Dimitar 10 years, 7 months ago.
-
Author
-
Hi,
I’m new in jqxgrid. I would like to add a button to the pager panel of my grid. I tried myself but somehow the button doesn’t work. My code is as below:$(“#pagerjqxgrid”).prepend(‘<div style=”float:left;margin-left:3px;”><button id=”reload”></button></div>’);
$(“#reload”).jqxButton();$(“#reload”).click( function(){
$(“#jqxgrid”).jqxGrid({ source: source });
});I’ve placed this code outside the source and jqxgrid definition.
Thanks in advanceHello maximus2014,
The grid pager can be customized via the pagerrenderer callback function. To see how, please check out the demo Custom Pager.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thank you Dimitar. That helped a lot.
Hi Dimitar,
How can i add a link or a button to the paging just before left arrow and after right arrow (I want First to be displayed before left and Last after right arrow ) .
I tried using page renderer but the problem there was it was not showing the number of records per page drop down . so i took the custom grid and tried adding using before() function of jquery for the class .But its not working.any suggestionsThanks & Regards
PrashanthHello prashanthpanyam,
Wouldn’t
pagermode: "simple"
be useful in your scenario? If you are not familiar with it, please check out the pagermode JSFiddle.Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Dimitar,
So which one should i go with..page renderer or normal grid.Hi prashanthpanyam,
If it suits you, go with normal grid with
pagermode: "simple"
.Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/thank you Dimitar, It worked.
And my another doubt is in page renderer , how i can i add a dropdownlist to show records per pageThanks and Regards
PrashanthHi Prashanth,
Here is how to implement this functionality (only the relevant part of pagerrenderer is given):
var pagerrenderer = function () { var element = $("<div style='margin-left: 10px; margin-top: 5px; width: 100%; height: 100%;'></div>"); var datainfo = $("#jqxgrid").jqxGrid('getdatainformation'); var paginginfo = datainfo.paginginformation; var leftButton = $("<div style='padding: 0px; float: left;'><div style='margin-left: 9px; width: 16px; height: 16px;'></div></div>"); leftButton.find('div').addClass('jqx-icon-arrow-left'); leftButton.width(36); leftButton.jqxButton({ theme: theme }); var rightButton = $("<div style='padding: 0px; margin: 0px 3px; float: left;'><div style='margin-left: 9px; width: 16px; height: 16px;'></div></div>"); rightButton.find('div').addClass('jqx-icon-arrow-right'); rightButton.width(36); rightButton.jqxButton({ theme: theme }); // records per page option var recordsPerPageDropDown = $("<div style='padding: 0px; margin: 0px 3px; float: left;'></div>"); var sizes = new Array(5, 10, 20); recordsPerPageDropDown.jqxDropDownList({ width: 100, height: 17, dropDownHeight: 80, placeHolder: "Page size", source: sizes }); recordsPerPageDropDown.on('select', function (event) { var args = event.args; if (args) { var item = args.item; var label = item.label; $('#jqxgrid').jqxGrid({ pagesize: parseInt(label) }); } }); recordsPerPageDropDown.appendTo(element); leftButton.appendTo(element); rightButton.appendTo(element);
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thank you very much Dimitar..
It WorkedRegards
PrashanthHi Dimitar, I’ve created a custom page renderer so that I can add two buttons in the pagination tab. While I ‘previous’ or ‘next’ page, the page info label is not updating. What may be the issue? My custom page renderer script is given below. Thanks in advance.
var pagerrenderer = function () {
var element = $(“<div style=’margin-top: 5px; width: 100%; height: 100%;’></div>”);
var datainfo = $(“#jqxgrid”).jqxGrid(‘getdatainformation’);
var paginginfo = datainfo.paginginformation;
// create navigation buttons.
var leftButton = $(“<div style=’padding: 1px; float: right;’><div style=’margin-left: 9px; width: 14px; height: 16px;’></div></div>”);
leftButton.find(‘div’).addClass(‘jqx-icon-arrow-left’);
leftButton.width(36);
leftButton.jqxButton();
var rightButton = $(“<div style=’padding: 1px; margin: 0px 3px; float: right;’><div style=’margin-left: 9px; width: 14px; height: 16px;’></div></div>”);
rightButton.find(‘div’).addClass(‘jqx-icon-arrow-right’);
rightButton.width(36);
rightButton.jqxButton();
// append the navigation buttons to the container DIV tag.
rightButton.appendTo(element);
leftButton.appendTo(element);
// create a page information label and append it to the container DIV tag.
var label = $(“<div style=’font-size: 11px; margin: 2px 3px; font-weight: bold; float: right;’></div>”);
label.text(“1-” + paginginfo.pagesize + ‘ of ‘ + datainfo.rowscount);
label.appendTo(element);
// records per page optionvar recordsPerPageDropDown = $(“<div style=’padding: 0px; margin: 0px 3px; float: right;’></div>”);
var sizes = new Array(500, 1000, 1500);
recordsPerPageDropDown.jqxDropDownList({ width: 55, height: 17, dropDownHeight: 80, source: sizes,selectedIndex: 1 });recordsPerPageDropDown.on(‘select’, function (event) {
var args = event.args;
if (args) {
var item = args.item;
var label = item.label;
$(‘#jqxgrid’).jqxGrid({ pagesize: parseInt(label) });
}
});
recordsPerPageDropDown.appendTo(element);
var recordsPerPageLabel = $(“<div style=’padding: 0px; margin: 0px 3px; float: right;’>Show Rows:</div>”);
recordsPerPageLabel.appendTo(element);// navigate to the next page when the right navigation button is clicked.
rightButton.click(function () {
$(“#jqxgrid”).jqxGrid(‘gotonextpage’);
var datainfo = $(“#jqxgrid”).jqxGrid(‘getdatainformation’);
var paginginfo = datainfo.paginginformation;
label.text(1 + paginginfo.pagenum * paginginfo.pagesize + “-” + Math.min(datainfo.rowscount, (paginginfo.pagenum + 1) * paginginfo.pagesize) + ‘ of ‘ + datainfo.rowscount);
});
// navigate to the previous page when the left navigation button is clicked.
leftButton.click(function () {
$(“#jqxgrid”).jqxGrid(‘gotoprevpage’);
var datainfo = $(“#jqxgrid”).jqxGrid(‘getdatainformation’);
var paginginfo = datainfo.paginginformation;
label.text(1 + paginginfo.pagenum * paginginfo.pagesize + “-” + Math.min(datainfo.rowscount, (paginginfo.pagenum + 1) * paginginfo.pagesize) + ‘ of ‘ + datainfo.rowscount);
});
//Refresh Button
var refreshButton = $(“<div style=’float: left;width:30px;’></div>”);
refreshButton.append(‘‘)
//refreshButton.jqxButton();
refreshButton.appendTo(element);
refreshButton.click(function() {
$(“#jqxgrid”).jqxGrid({ source: source });
$(“#datespan”).html(‘Selected ‘+start_date+’ to ‘+end_date);
$(“#active”).html(‘ [‘+selectedRows);
$(“#total”).html(totalRows);
});
//Search Button
var searchButton = $(“<div style=’float: left;width:30px;’></div>”);
searchButton.append(‘‘);
searchButton.appendTo(element);// return the new pager element.
return element;
}Hi maximus2014,
If your pagechanged binding looks like this:
$("#jqxgrid").on('pagechanged', function () { var datainfo = $("#jqxgrid").jqxGrid('getdatainformation'); var paginginfo = datainfo.paginginformation; self.label.text(1 + paginginfo.pagenum * paginginfo.pagesize + "-" + Math.min(datainfo.rowscount, (paginginfo.pagenum + 1) * paginginfo.pagesize) + ' of ' + datainfo.rowscount); });
you should add the label to the self object:
var label = $(“<div style=’font-size: 11px; margin: 2px 3px; font-weight: bold; float: right;’></div>”); label.text(“1-” + paginginfo.pagesize + ‘ of ‘ + datainfo.rowscount); self.label = label; label.appendTo(element);
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar, I tested as per your suggestion, but the error persists.On clicking the button number is changed but on paging completion the initial data is displayed. Where should I place the ‘pagechanged’ function. I’ve placed it outside the paging button click. Thanks in advance.
Hi maximus2014,
Please post all the relevant code you have and remember to format it first by selecting it and pressing the
code
button from the toolbar.Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.