Server-side integration is possible with Webix data components, client-side data stores (called Data Collections) and forms. It is enabled in several ways:
You can launch Node.js server-side samples provided in the Webix package. After you downloaded the package, run the following commands:
npm install
npm run server
There are several packages of samples intended for illustrating the ways of using Webix with different server-side platforms:
Basic client-side code that enables loading data to a component during its initialization is as follows:
webix.ui({
id:"dtable",
view:"datatable",
url:"data.php"
});
Or, to load data after component initialization, apply load() method to it:
$$("dtable").load("myscript.php", "xml");
Note that
More info about custom scripts is in the dedicated article.
To load data from MongoDB, you might need to convert _id to id (the identifier in Webix). You can do it when you load data using a proxy. However, you can extend DataStore id method and use the primary key _id to set the id for incoming objects in order to improve performance.
webix.DataStore.prototype.id = function (data) {
data.id = data._id || data.id || webix.uid();
return data.id;
}
Basic client-side code that enables data saving from a component to database is as follows:
webix.ui({
id:"dtable",
view:"datatable",
save:"save_script.php"
});
Note that
In addition, the save property automatically initializes DataProcessor for this component, so that data changes are transmitted to your saving script. DataProcessor listens to component events, defines the editing operation (as insert, update and delete one) and sends changed data to a server script in a POST request.
Defining Operation Type
By default, the operation status comes as webix_operation in a POST request. Usually, a saving script is single and contains patterns for different operations.
At the same time you can define a specific script for each operation. DataProcessor will define the type of an operation, and the necessary script will be executed:
save:{
"insert":"data/insert.php",
"update":"data/update.php",
"delete":"data/delete.php"
}
Related sample: Server-side Integration: Custom URL
If you need to change the default pattern of data processing, look up Dataprocessor docs.
If you use Webix Uploader, you may wonder about how saving of the files is performed.
{
view:"uploader",
id:"uploader1",
name:"uploader"
upload:"upload.php"
autosend:false
}
$$("uploader1").send();
Note that
Form data are either
Related sample: Form: Saving Data to Server