Hi,
I am trying to work on a sample whereby I read data locally into the DataSource but I submit changes to server.
Here is a dojo, however, an exception occurs when a call for dataSource.sync() is executed.
Any idea why that is happening?
http://dojo.telerik.com/@bhaidar/AYALi
Thanks
I am trying to work on a sample whereby I read data locally into the DataSource but I submit changes to server.
Here is a dojo, however, an exception occurs when a call for dataSource.sync() is executed.
Any idea why that is happening?
http://dojo.telerik.com/@bhaidar/AYALi
Thanks
10 Answers, 1 is accepted
0
Hi Bilal,
The error occurs because mixing functions and objects for the transport operations is not supported. Basically, each operation should be of the same type as the "read", which in this case is a function.
Regards,
Alexander Popov
Telerik
The error occurs because mixing functions and objects for the transport operations is not supported. Basically, each operation should be of the same type as the "read", which in this case is a function.
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bilal
Top achievements
Rank 2
answered on 25 Mar 2015, 10:08 AM
Is there a workaround? I already have the data locally, however, I want to update on the server any changes that occurred on the client.
Thanks
Thanks
0
Hello Bilal,
Sure, the workaround is to use a function for the Update as well and make and Ajax request that sends the data to the server. You can find an example in the transport.update documentation.
Regards,
Alexander Popov
Telerik
Sure, the workaround is to use a function for the Update as well and make and Ajax request that sends the data to the server. You can find an example in the transport.update documentation.
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bilal
Top achievements
Rank 2
answered on 28 Mar 2015, 07:59 PM
Hi,
I am trying to send extra data to server with a create/update custom function.
Any idea on how to do so? I want to send a single key/value.
Thanks
I am trying to send extra data to server with a create/update custom function.
Any idea on how to do so? I want to send a single key/value.
Thanks
0
Bilal
Top achievements
Rank 2
answered on 29 Mar 2015, 10:55 PM
Hello,
I managed to send extra data. However, I would like to share with you a behavior I am facing with the below implementation:
What I realized, as long as the response has code 200 OK, the success function of $.ajax is the only function called.
In my case, I am returning errors when creating/updating data on server. However, I am returning 200 OK and adding errors as a property on the response data.
So for this, I had always to work with success function and check if errors are present, if so, then I call options.error(results);
The error function of $.ajax is never used. Are there cases it will be used?
Moreover, when options.error is called, the error function defined on DataSource is fired however, the input for that function doesn't contain the data I sent when I called options.error(result). Why is that? Shouldn't the data I passed in to options.error be passed in to the DataSource error function?
Moreover, I realized that when options.error() is called, the Grid doesn't cancelChanges, all changes done by user are kept the same.
Also, I tried to implement the DataSource error function, whereby I bind one time to Grid using jquery .one, however, it was never fired, but fired when I click on cancelChanges on Grid.
In general, is the above reliable to work with? In my case, I am loading data outside DataSource and hence the need to use this method.
Thank you
I managed to send extra data. However, I would like to share with you a behavior I am facing with the below implementation:
stateMap.projectStaffDs =
new
kendo.data.DataSource({
transport: {
read:
function
(options) {
options.success(stateMap.projectStaff);
},
create:
function
(options) {
$.ajax({
cache:
false
,
type:
"POST"
,
url: document.getBaseUrl() +
"/Services/SaveStaff"
,
contentType:
"application/json; charset=utf-8"
,
dataType:
"json"
,
data: JSON.stringify({ data: options.data.models, workspace: stateMap.userWorkspace.workspaceName }),
success:
function
(result) {
if
(result.errors) {
options.error(result);
}
else
if
(result.staff) {
options.success(result.staff);
}
},
error:
function
(result) {
options.error(result);
}
});
}
},
schema: {
model: projectStaffModel
},
batch:
true
,
pageSize: 1000
});
What I realized, as long as the response has code 200 OK, the success function of $.ajax is the only function called.
In my case, I am returning errors when creating/updating data on server. However, I am returning 200 OK and adding errors as a property on the response data.
So for this, I had always to work with success function and check if errors are present, if so, then I call options.error(results);
The error function of $.ajax is never used. Are there cases it will be used?
Moreover, when options.error is called, the error function defined on DataSource is fired however, the input for that function doesn't contain the data I sent when I called options.error(result). Why is that? Shouldn't the data I passed in to options.error be passed in to the DataSource error function?
Moreover, I realized that when options.error() is called, the Grid doesn't cancelChanges, all changes done by user are kept the same.
Also, I tried to implement the DataSource error function, whereby I bind one time to Grid using jquery .one, however, it was never fired, but fired when I click on cancelChanges on Grid.
In general, is the above reliable to work with? In my case, I am loading data outside DataSource and hence the need to use this method.
Thank you
0
Hello,
When will the error callback be triggered is described in the jQuery ajax method documentation.
As for passing the errors to the error event - you should set the field in the response that holds the errors with the schema.errors option and call the success callback:
Regards,
Daniel
Telerik
When will the error callback be triggered is described in the jQuery ajax method documentation.
As for passing the errors to the error event - you should set the field in the response that holds the errors with the schema.errors option and call the success callback:
success:
function
(result) {
if
(result.errors) {
options.success(result);
}
else
if
(result.staff) {
options.success(result.staff);
}
}
schema: {
model: projectStaffModel,
errors:
"errors"
}
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bilal
Top achievements
Rank 2
answered on 01 Apr 2015, 07:01 PM
Hi Daniel,
I added that field. I was able to access the errors collections as this:
args.xhr.errors
There was no args.errors
Is there something wrong still?
Thanks
I added that field. I was able to access the errors collections as this:
args.xhr.errors
There was no args.errors
Is there something wrong still?
Thanks
0
Hello,
Did you trigger the success or the error callback? The errors will be set to the xhr field if you have triggered the error callback.
Regards,
Daniel
Telerik
Did you trigger the success or the error callback? The errors will be set to the xhr field if you have triggered the error callback.
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bilal
Top achievements
Rank 2
answered on 03 Apr 2015, 01:16 PM
I was reviewing your post, you used options.success for both cases? Even when there are errors, you are calling success method? Why is that? Shouldn't i call options.error?
Thanks
0
Accepted
Hi,
The error callback signifies that the request has failed which is not the case when using custom errors.
Regards,
Daniel
Telerik
The error callback signifies that the request has failed which is not the case when using custom errors.
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!