This is a migrated thread and some comments may be shown as answers.

Update not called when syncing the datasource

10 Answers 1993 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Ewald
Top achievements
Rank 1
Ewald asked on 18 Jan 2014, 10:37 PM
I have trouble to update my datasource when the grid is edited.
See the following jsfiddle: http://jsfiddle.net/ewaldhofman/uU2th/8/

The update method in the transport of the datasource is never called when the value in the grid is updated.

What am I doing wrong?

10 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Popov
Telerik team
answered on 20 Jan 2014, 09:24 AM
Hi Ewald,

I would recommend specifying the field types and adding an ID field in the DataSource schema option. Since there is no ID specified the Grid cannot determine which fields are new or modified, thus neither the update nor the create methods are called. You can find an updated example here.

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
Accepted
Nathan
Top achievements
Rank 2
answered on 20 Jan 2014, 06:50 PM
When I've done automatic updating in the grid I always have my model/schema defined. I updated your fiddle to have an ID field and also make sure that the model is set so that the column is editable. The update message comes up now.

http://jsfiddle.net/uU2th/9/

Hope that helps!
0
Ewald
Top achievements
Rank 1
answered on 24 Jan 2014, 04:46 AM
Thanks. That was the missing piece!
0
King Wilder
Top achievements
Rank 2
answered on 25 Apr 2014, 09:37 PM
Leave it to me to find problems, but I think I found one.

When I modified the "update: function" to this:

update: function(options) {
    alert('update: ' + kendo.stringify(options));
}

... you'll see that when you tab out of the field, the new number is NOT reflected in the data that is passed to the Update method.  The old value is passed.  This can cause serious problems if it is updating a database onBlur.

Any ideas how to get the new values?

Thanks,

King Wilder
0
Alexander Popov
Telerik team
answered on 29 Apr 2014, 10:54 AM
Hello King Wilder,

I would recommend enabling the DataSource's autoSync option instead of calling the sync method from within the Grid's save event handler. Here is an updated example showing what I mean.

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
King Wilder
Top achievements
Rank 2
answered on 29 Apr 2014, 04:09 PM
Alexander,

Yes that does work.  I guess I have a question then, why does the ds.sync() inside the "save" method not return the actual form values? Doesn't that mean that the data returned by the datasource is not current?  What's different about how the autoSync works than the sync method?

Thanks,

King Wilder
0
Alexander Popov
Telerik team
answered on 30 Apr 2014, 12:42 PM
This happens because the model is updated after the save event handler is executed, and the difference is when the sync method is called.

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
King Wilder
Top achievements
Rank 2
answered on 30 Apr 2014, 09:48 PM
Alexander,

Are you saying that in my previous example of it showing the old data, that it gets updated after when my alert occurred, but before being passed to the datasource for syncing?

Thanks,

King Wilder
0
Alexander Popov
Telerik team
answered on 01 May 2014, 12:12 PM
Not exactly. The original data would still end up in Ajax request (if we assume there is one in the transport update method) if the sync method is called from within the save event handler. The sync should be called after the save event handler to get this working. Here is a screencast showing a couple of scenarios - I hope it helps my explanation. 

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
King Wilder
Top achievements
Rank 2
answered on 01 May 2014, 03:24 PM
Yes, perfect example.  That makes it clear.  I understand now.  I'm still trying to understand the little nuances of how your framework works.  :^)

Thanks,

King Wilder
Tags
Data Source
Asked by
Ewald
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Nathan
Top achievements
Rank 2
Ewald
Top achievements
Rank 1
King Wilder
Top achievements
Rank 2
Share this question
or