Update not called when syncing the datasource

11 posts, 2 answers
  1. Ewald
    Ewald avatar
    9 posts
    Member since:
    Jan 2014

    Posted 18 Jan 2014 Link to this post

    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?
  2. Answer
    Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 20 Jan 2014 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Answer
    Ewald
    Ewald avatar
    9 posts
    Member since:
    Jan 2014

    Posted 20 Jan 2014 Link to this post

    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!
  5. Ewald
    Ewald avatar
    9 posts
    Member since:
    Jan 2014

    Posted 23 Jan 2014 Link to this post

    Thanks. That was the missing piece!
  6. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 25 Apr 2014 Link to this post

    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
  7. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 29 Apr 2014 Link to this post

    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!
     
  8. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 29 Apr 2014 in reply to Alexander Popov Link to this post

    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
  9. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 30 Apr 2014 Link to this post

    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!
     
  10. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 30 Apr 2014 in reply to Alexander Popov Link to this post

    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
  11. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 01 May 2014 Link to this post

    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!
     
  12. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 01 May 2014 in reply to Alexander Popov Link to this post

    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
Back to Top
Kendo UI is VS 2017 Ready