Data can be loaded to non-hierarchical components in portions:
1. Firstly, a limited number of records is loaded.
2. Then, data are loaded at the moment when:
Currently dynamic loading for linear data are implemented for the following components: DataTable, DataView and List (you need to set the dynamic:true property for the List widget).
To enable dynamic data loading you need to:
1. Set the component data source that will load initial data. It can be done either with the help of url property or load method;
webix.ui({
id:"dview",
view:"dataview",
url:"data/data_dyn.php"
});
//or
$$("dview").load("data/data_dyn.php");
2. Optionally, define various aspects of dynamic loading such as:
webix.ui({
view:"dataview",
datafetch:50,
datathrottle: 500,
loadahead:100
});
When scrolling or pagination occurs, the component will automatically issue a request based on the data source, e.g. "data/data_dyn.php?continue=true&count=100&start=130" where:
Note that your server script should be able to handle these parameters.
Server-side response should include the following information:
Sample of JSON response
{
"data":[
{"id":1,"package":"acx100-source"},
{"id":2,"package":"acx200-source"}
],
"pos":0,
"total_count":999
}
The loadNext method can be used to send a request that loads the specified number of records and parses them into the component. The arguments are:
Using URL set in the component constructor
webix.ui({
id:"grida",
view:"datatable",
url:"data/data_dyn.php"
});
$$("grida").loadNext(10, 0);
Related sample: Dynamic Loading with Removing the Existing Content
Using given URL
$$("gridb").loadNext(50,900,function(){
this.showItem(903);
}, "data/data_dyn.php");
Related sample: Setting Loading Position
The method allows the following scenarios:
$$("grida").loadNext(30, pos, function(){
this.showItemByIndex(pos);
pos += 30;
});
// pos - index of the last data item
Related sample: Dynamic Loading with Appending Content
webix.ui({
view:"datatable",
"data->onParse":function(){
this.clearAll();
this.data.url = "data/data.php";
}
});
$$("grida").loadNext(10, base);
// base - index of the last data item
Related sample: Dynamic Loading with Removing the Existing Content
You can capture the moment just before a dynamic loading request is sent to server with the help of an onDataRequest event.
It can be used to cancel the default behavior and issue a custom data request:
$$("dtable").attachEvent("onDataRequest", function(start, count){
var data = custom_load_data(start, count);
this.parse(data, "json");
return false;
});