Paging helps present numerous items from the dataset dividing them into groups to display on separate pages. It is used in conjunction with data components like dataview, datatable and list.
Pager can be initialized as:
In both cases pager can be placed into its own HTML container different from that of the associated component.
The main properties of a pager object:
If a component container is too small to display the number of items specified by the size config, a scrollbar appears.
Related sample: Paging Animation
With dynamic loading, only part of the stored records is loaded into the component during initialization. Each time you page through the component, a data request is sent to the server to load the next portion of data.
Related sample: Dynamic paging. Loading from DB
Read more about dynamic loading.
In this case pager is initialized as a separate component in layout and is linked to the datatable by its ID.
webix.ui({
rows:[
{
view:"datatable",
columns:[ ...],
pager:"pagerA", //linking to a pager
},
{
view:"pager", id:"pagerA",
size:50,
group:5
}
]
})
Related sample: Visible Pager in Layout
When pager is used as a standalone view, the size property can be combined with either the limit or the count property to set the total values for the pager, namely:
You can as well use Webix pager as a separate entity without a master component, and provide a fully custom logic for it - go to the end of the article for details.
Here the pager object appears to be the property of a datatable and includes its own parameters:
webix.ui({
view:"datatable",
columns:[...],
pager:{
size:50,
group:5,
level:1,
template:function(){}
}
});
Related sample: Level-based pager
If you want more than one pager for the component, for instance, pagers above and below the view, there should be two containers in HTML layout, or two views with pager instances. The two pagers must be linked to each other with the help of the clone method.
You can clone both standalone pagers and those included into the component constructor.
Cloning a standalone pager
// an identical pager
$$("pagerA").clone($$("pagerB"));
// a pager with some properties of its own
$$("pagerA").clone({
container:"pagingB_here",
size:50,
group:5
});
Related sample: Two-area Pager
With a component pager, you need to get the pager object with the getPager() method:
Cloning a component pager
grida.getPager().clone({
container:"paging_here_too",
size:10,
group:5
});
Related sample: Defining Several Pagers on a Page
Cloned pagers will change their values simultaneously!
Paging can be implemented through an invisible pager, which gives you the ability to control the process by custom functions and create your own "Next/Previous Page", "Jump to Start/End" buttons, etc. instead of a standard pager.
For these needs, you should include the apiOnly parameter with the true value into the pager constructor, whether it is initialized as a separate view or as a component's property.
Datatable with Invisible Pager
view:"datatable",
pager:{
id:"pagerA",
apiOnly:true, //makes pager invisible
size:50,
group:5
}
In this case, the dedicated buttons will help us page:
Next Page Button
<input type='button' value='next page' onclick='next_page()'>
function next_page(){
$$("pagerA").select("next");
}
Related sample: Non-visible Pager
The select() function can take the index of the desired pager (zero-based numbering,) or its order ("next", "prev", "first", "last").
By default, a pager looks as a set of numbered squares accompanying the component. But at the same time you can change the pattern with the help of a custom template:
Template elements may include the following elements:
pager: {
template: "{common.prev()}{common.next()}Page {common.page()} from #limit#"
}
Related sample: Custom Pager Template
You can use HTML elements as a base for a custom pager that includes both HTML tags and pager properties in its template.
Properties of the component pager are stored in the data object, pager templates reside in the common object:
pager:{
template:function(data, common){
var current = data.page + 1;
var html = "<select onchange='grida.setPage(this.value-1)'"+
"style='text-align:center; width:150px'>";
for (var i=1; i<=data.limit; i++)
html+="<option "+(i == current?"selected='true'":"")+">"+i+"</option>";
html+="</select> from "+data.limit;
return html;
},
container:"paging_here",
size:10,
group:5
}
By default, pager uses recognizable signs to display order buttons (first, last, prev, next).
Default Locale
webix.i18n.pager = {
first: "<span class='webix_icon wxi-angle-double-left'></span>",
last: "<span class='webix_icon wxi-angle-double-right'></span>",
next: "<span class='webix_icon wxi-angle-right'></span>",
prev: "<span class='webix_icon wxi-angle-left'></span>"
};
Pager localization allows using words of any language for these buttons:
Custom Locale
webix.i18n.pager = {
first: "First",
last: "Last",
next: "Next",
prev: "Prev"
};
Related sample: Pager Localization
Animation it switched on by the animate property. Set to true, it allows scrolling through the view in the X or Y mode, depending on the scroll value of the main component.
Animation can take various effects when they are stated in the animate constructor through the type, subtype and direction parameters.
pager: {
animate:{
direction:"top",
type:"flip"
}
}
Related sample: Paging Animation Types
Learn more about animation types and subtypes in the corresponding chapter of the manual.
Here we treat two tasks:
1 . How to ensure that the number of records per page equals to the number of records the component can display?
The number of records per page is stated by the size:{number} parameter of a pager.
At the same time, the number of records can be limited in the component itself by the following parameters:
All you need is to make these two parameters the same:
rows:[
{
view:"pager",
id:"pagerA",
size:10
},
{
view:"datatable",
columns:[...],
pager:"pagerA",
yCount:10
}
]
Related sample: Adjusting Component Size to Page
2 . How to adjust the component size to the page size?
To adjust the number of records shown per page to the size of parent HTML container and, hence, to the component's height, you should let pager autosize.
<div id="testA" style='height:600px; width:300px;'></div>
webix.ui({
rows:[
{
view:"pager",
id:"pagerB",
autosize:true,
group:5
},
{
view:"list",
pager:"pagerB",
container:"testA"
}
]
});
Related sample: Adjusting Page Size to Component Size
Getting Pager Object
$$("datatable1").getPager();
Getting Current Page
Note that you'll get the page index (zero-based numbering), so add 1 to get the actual page number.
$$("datatable1").getPage();
//or, using the pager object
$$("pagerA").config.page;
Setting (Opening) Page
To switch to the necessary page, specify the page index within the dedicated method:
$$("datatable1").setPage(2); // makes the third page visible
or select the needed page:
$$("datatable1").getPager().select(2); // selects the third page
Pager can be used without a master component for creating custom logic. To render such a pager, the following code should be used:
webix.ui({
view: 'pager',
template: '{common.prev()} {common.pages()} {common.next()}',
master:false,
size: 50,
group: 5,
count: 1000,
on: {
onItemClick: function(id, e, node) {
//..some custom logic..
}
}
});
The template parameter can be omitted in favor of the default template.
Related sample: Standalone Pager
Note that the count and size parameters should be used anyway, count divided by size equals to the total number of pages.