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

autoSync + Remote dataSource = duplicates

6 Answers 417 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 27 Jun 2017, 05:26 PM

Enabling autoSync on a remote dataSource creates duplicates of items...  (apologies for the formatting.  The inline code formatting widget is not good, and I cannot do a dojo example, because it depends on a remote service).   The result of clicking the button is...

 

{
"Customer": "Item 1",
"id": 1
},
{
"Customer": "Item 1",
"id": 2
},
{
"Customer": "Item 2",
"id": 3
},
{
"Customer": "Item 1",
"id": 4
},
{
"Customer": "Item 2",
"id": 5
},
{
"Customer": "Item 3",
"id": 6
}

 

 

 

$(function () {
$.ajax({
url: "http://localhost:3000/project/2"
}).then((data) => {
let dataSource = new kendo.data.DataSource({
autoSync: true,
transport: {
read: {
url: "http://localhost:3000/customer",
type: "GET"
},
create: {
url: "http://localhost:3000/customer",
type: "POST"
}
},
schema: {
model: {
id: "id"
}
}
});
$("#button").kendoButton({
click: (e) => {
dataSource.add({ Customer: "Item 1" });
dataSource.add({ Customer: "Item 2" });
dataSource.add({ Customer: "Item 3" });
}
})
});
});

 

 

Turning off autoSync and manually syncing the dataSource works as expected.

6 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 29 Jun 2017, 10:04 AM
Hello Doug,

This is expected because when autoSync is on, it will make three separate requests for the new items, but the success for the first item will not be received before the other once are sent. This will create a scenario where the Grid is still sending the first and the second items as new and duplicate them on the server.

If there is enough time to receive the success callback before adding a new item, they will be added only once as expected.

I made an example just for demonstrating purposes of illustrating the scenario:

http://dojo.telerik.com/ObOnAL/2

Let me know if you need additional information on this matter.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Doug
Top achievements
Rank 1
answered on 11 Jul 2017, 06:02 PM
Thanks for your response.  I understand your explanation for why it works that way.  However, I think this should be considered a defect and addressed.  Duplicating data should not be considered functioning as designed in any case.
0
Stefan
Telerik team
answered on 13 Jul 2017, 05:27 AM
Hello Doug,

I do understand that this is not expected, but it is implemented this way because otherwise, it can lead to data loss which is again not desirable.

I will forward this to the developer's team for consideration, but for now, this is the designed way and changing it can lead to a breaking change in the Grid.

Apologies for the inconvenience this may cause you.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Hannah
Top achievements
Rank 2
answered on 01 Oct 2019, 09:53 PM

Stefan,

I am very disappointed to hear that you do not recommend using incell editing with autosync in the kendo grid datasource.

I have a unique requirement from my users, so I have to make this behavior work somehow. Unfortunately, the update controller gets called twice. I have constraints in the database that prohibit multiple records being created, but I am not able to implement error-handling (to warn user of concurrency issues), because they will get error messages every time they delete or add a record (DELETE errors second time because the record no longer exists, and ADD errors second time because the record already exists and can't be duplicated).  Is there some workaround to make autoSync work with incell editing without calling the controller more than once?

Hannah

0
Hannah
Top achievements
Rank 2
answered on 02 Oct 2019, 03:19 PM
Additionally, I would add that even with ONE item in the grid the update controller gets called twice.
0
Alex Hajigeorgieva
Telerik team
answered on 03 Oct 2019, 02:22 PM

Hi, Hannah

There is something you could try depending on the use case - you can temporarily disable the grid editing capability using the data source events: 

https://dojo.telerik.com/@bubblemaster/ElugUfET/2

              requestStart: function(){
                  $(".k-grid").css("pointer-events", "none");
                },
                requestEnd: function(){
                  setTimeout(function(){
                    $(".k-grid").css("pointer-events", "auto");
                  });                  
                }

Regards,
Alex Hajigeorgieva
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Data Source
Asked by
Doug
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Doug
Top achievements
Rank 1
Hannah
Top achievements
Rank 2
Alex Hajigeorgieva
Telerik team
Share this question
or