Intermediate

REST Mode Support

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

You can as well initialize REST proxy object and set is 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");

REST Load and Save Pattern

  • On loading a GET request is executed and data in any of the supported data formats are returned;
  • When editing happens or the update() method is called, a PUT request is generated, and the ID of the item and other parameters are sent to the script. The item ID is shown in the address line;
  • When an item is added inside the component, a POST request is generated, and the ID of the item and other parameters are sent to the script. The item ID is shown in the address line;
  • When an item is removed from the component, a DELETE request is generated, and the ID of the item is sent to the script.

The saving script treats adding, editing and deleting operations separately and should contain different code on the base of a request method.

Server-Side Response

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", ...}

Response Types

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