Hi, I'm using a ClientDataSource with a Grid to communicate with a webservice from client-side.
The webservice returns a custom response for any request: {"ErrorMessage":(error message or null),"IsSuccessful":(boolean),"Result":[(result of request)]}.
In the ClientDataSource I defined the schema as follows to check for server errors
<
Schema
DataName
=
"Result"
ResponseType
=
"JSON"
ErrorsName
=
"ErrorMessage"
>
<
Model
ID
=
"id"
>
</
Model
>
</
Schema
>
And this function to show the error:
function
dataSource_error(e) {
e.preventDefault();
console.log(
"Error"
, e);
serverNotification.set_title(
"Server Error"
);
serverNotification.set_text(e.errors);
serverNotification.update();
serverNotification.show();
}
My problem is that when I try to remove an item from the clientdatasource and I get a custom error,the item is still removed from the clientdatasource and the grid which is not an effect I'm looking for.
For the clientdatasource remove/destroy I'm using a function:
dataSource.transport.destroy =
function
(options) {
console.log(
"Options-destroy"
, options);
console.log(dataSource);
$.ajax({
url: (
"<%= WebApp.WebServiceHelper.BASE_WS_URL + WebApp.WebServiceHelper.WS_CLOSE %>"
),
dataType:
"json"
,
data: {
username: sessionStorage[
"username"
],
},
success:
function
(result) {
console.log(
"result-destroy:"
, result);
//if (result.IsSuccessful) {
options.success(result);
//} else {
// options.error(result);
//}
console.log(
"Options-destroy-success"
, options);
console.log(dataSource);
},
error:
function
(result) {
console.log(
"result1-destroy:"
, result);
options.error(result);
}
});
};
Before adding ErrorsName in the schema I was check the IsSuccessful on success and call options.error, in this case the clientDataSource remove the item but the grid did not rebind !
On the same topic is it possible to check if IsSuccessful is false instead of ErrorMessage is null to generate an error and get the error message from ErrorMessage?
In case of remove, the Result will be a boolean, can I also prevent the clientDataSource from removing an element if if Result is false?