Intermediate

REST Mode Support

Webix features full support for REST load and save protocol.

To enter REST mode, use prefix rest before load and save 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 webix.proxy() function receives 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 GET request is executed and data in any of supported data formats is returned;
  • When editing happens or update() method is called - PUT request is generated, item ID and other parameters are sent to the script. Item ID is shown in the address line;
  • When item is added inside the component - POST request is generated, item ID and other parameters are sent to the script. Item ID is shown in the address line;
  • When item is removed from the component - DELETE request is generated, item ID is sent to the script.

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

Server-Side Response

Server-Side response is set the same as with any custom script.

Note that Webix DataProcessor can be tuned to update client-side data from 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 as:

{"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