Validating edits from datatable on the server.

I have the following scenario:

An datatable with some editable columns which validate for input on the client with the webix rules. There are columns though, that cannot be validated on the client, but on the server only (ie for unique id/code).

An approach would be to create a rule and validate with webix.ajax in synchronous mode that I would prefer to avoid this at all means.

I thought I could validate on ‘save’. The server can return a status response with error or success. I can catch this with onAfterUpdate event of the datatable (correct me if there is a better way, but it works this way).
At this point, I would like to display a validation error on the datatable if the server script returns an error status and mark the row (and possibly the corresponding column/cell) with error.
I thought I could use the callEvent method on the datatable and fire a onValidationError event but I didn’t manage to make that work.

save: {
url: “save.php”,
autoupdate: true,
on:{
onAfterUpdate:function(response, id, details) {
if (response.status == ‘error’)
myDataTable.callEvent(‘onValidationError’);
}
}
}

The documentation states that I can pass some parameters to the event from callEvent but I could not find any specification on the docs. The code above does not work (the event is not fired).

Have also tried to catch error status from server with onAfterSaveError but it does not fire with a status:“error” response from the server.

So the question is: How can I fire a onValidationError event for the datatable using callEvent?

or what would be another approach to use webix to show the error on the datatable with validation on the server side?

Thank you.

Have also tried to catch error status from server with onAfterSaveError but it does not fire with a status:“error” response from the server.

Of course, you can validate data on save, but you need to be aware of the following things:

The onAfterUpdate event will fire only in case of successful serverside response { status:"success"}.

So, you should use either onAfterSync (fires anyway) or onAfterSaveError (fires on {status:"error"} response) event.

Parameters for the called event are passed in the array as a second argument of the callEvent method.

Please, consider the snippet:

view:"datatable", 
id:"mydatatable",
...
save: {
  url:"server/datatable_save.php",
  on:{
    onAfterSaveError:function(id,status,response, details){
	if(response.status =="error")
	   $$("mydatatable").callEvent("onValidationError", [id]);
	}
   }
},
on:{
  onValidationError:function(id){
     console.log(id);
  }
}

Serverside response for the above scenario should look like:

echo '{ "id":"'.$id.'", "status":"error" }';

Thank you Helga,

onAfterSaveError does the trick. It even fires for any response status other than success which is a good thing, since we can handle different response types, for example:

status = 'error' when there is something went wrong on the server side or
status = 'invalid' when data entered are not validated on the server.

It’d be nice if I could revert the cell back to its original value before the user updates (since the grid would display non-synced value on the cell) but I could not figure this out. Tried this.reset() but it would not work.

You can enable automatic data revert on saving error
http://docs.webix.com/api__dataprocessor_undoonerror_config.html

Check the undo functionality if you need a more granular control.