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

dataSource.sync() callback

5 Answers 722 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
DJo
Top achievements
Rank 1
DJo asked on 19 Apr 2013, 07:55 PM
Can I add a callback function to the dataSource sync() method? I want code to wait until after the sync() is finished before proceeding because subsequent code is querying the data that is updated by the sync().

I don't want to use the dataSource's change event because I need to stay in scope where I manually call the sync() method.

5 Answers, 1 is accepted

Sort by
0
DJo
Top achievements
Rank 1
answered on 19 Apr 2013, 08:37 PM
Solved it myself. I did use the sync event, which turned out to have some advantages.
0
DJo
Top achievements
Rank 1
answered on 30 Jul 2013, 09:05 PM
Change my mind. This would be really useful and in keeping with jQuery norms.

Is there a way to add a callback function to the dataSource.sync() method? I want to sometimes execute a function after sync but not always.
0
Rosen
Telerik team
answered on 01 Aug 2013, 12:09 PM
Hello DJo,

I'm afraid that such callback is not available. As you have already noted the sync event should be used instead. You may know it is possible to use the one method to attach a event handler only once when it is required.
Other useful events in this case are change event (which in this case will have e.action argument set to sync), as well as requestEnd event which is raised before data is processed, providing access to the raw response.

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
AJ
Top achievements
Rank 1
answered on 18 Nov 2016, 06:25 PM

Hello, I just wanted to update this post since the sync function now returns a promise.  So, you can do something like this:

myGrid.dataSource.sync().then(function() {

    //callback logic in here

});

0
Vivek
Top achievements
Rank 1
answered on 28 Feb 2020, 09:04 AM
Thank you AJ. sync.then works :)
Tags
Data Source
Asked by
DJo
Top achievements
Rank 1
Answers by
DJo
Top achievements
Rank 1
Rosen
Telerik team
AJ
Top achievements
Rank 1
Vivek
Top achievements
Rank 1
Share this question
or