Webix features full support for the REST load and save protocol.
To enter the REST mode, use the prefix rest before the loading and saving scripts. This will enable the necessary proxy object.
{
view:"datatable",
// config
save: "rest->server/datatable_rest.php",
url: "rest->server/datatable.php"
}
Related sample: Datatable: REST-ful Saving
You can as well initialize REST proxy object and set it as the value of the url and save properties. For these needs the webix.proxy() function receives the rest prefix and path to your server-side save script.
var rest = webix.proxy("rest", "server/datatable_rest.php");
The saving script treats adding, editing and deleting operations separately and should contain different code on the base of a request method.
A server-side response is set the same way as with any custom script.
Note that Webix DataProcessor can be tuned to update client-side data from a response automatically:
view:"datatable",
save: {
url:"rest->server/datatable_rest.php",
autoupdate:true
}
A short response in the JSON format:
{"status":"ok"}
//or
{"tid":121}
A more complex example can look like this:
{"action":"update", "id":15, "newid":15}
If you need to return an error, the response should be as follows:
{"action":"error", ...}
The following types of response are predefined: update, insert, delete, invalid and error.
You can pass any data in a JSON response. Besides, the response can be received on the client side by means of the onAfterUpdate event.
Back to top