I have a REST-service made using Apigility. It returns data in json, in a specific format. (See apigility.org).
I can easily make the datatable consume these data, by making a new datadriver.
However, the REST-service will always return pages of data: 25 records on each page, and starting on page boundaries. I can configure the amount of records on a page, but I cannot get it to start on arbitrary pages.
A datatable can attach the starting point and record count the the url when requesting more data. But can I configure it to always have the start-value be on a page boundary? Making the start-parameter always be a multiple of 25?
Yes, the simplest case, if you are using the built-in paging, just set the page size to 25
webix.ui({
rows:[
{
view:"datatable",
pager:"pagerA", //linking to a pager
},
{
view:"pager", id:"pagerA",
size:25,
group:5
}]
})
If you want to load data during scrolling, not a real paging, you can use onDataRequest event handler, intercept default loading call and set your own start and count values
Thanks for the hints. I’m trying to load data during scrolling.
But I cannot get the onDataRequest to work. When I place and ajax-call inside it, and tries to parse the returned data into the datatable, it goes into an endless loop.
Do you need to get the actual size from a paging control, or do you need to apply the size from the data.page_size to the pager?
DataDriver is isolated from a component, so it will be hard to access any controls from there without using hardcoded IDs. You can add the event handler to component which uses paging,
table.data.attachEvent("onParse", webix.bind(function(driver, data){
//call method of driver, or read data from driver and change the UI here
//this.config.pager will reffer to the related paging control
}, table));
I think the latter - the webservice that I get my data from, will deliver it in pages, each time also in the returned JSON, it will tell me how many items on a page.
I would like this pagesize, from the JSON, to be used by the component.