autoSync + Remote dataSource = duplicates

4 posts, 0 answers
  1. Doug
    Doug avatar
    10 posts
    Member since:
    Mar 2014

    Posted 27 Jun Link to this post

    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.

  2. Stefan
    Admin
    Stefan avatar
    1147 posts

    Posted 29 Jun Link to this post

    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 visualization (charts) and form elements.
  3. Doug
    Doug avatar
    10 posts
    Member since:
    Mar 2014

    Posted 11 Jul in reply to Stefan Link to this post

    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.
  4. Stefan
    Admin
    Stefan avatar
    1147 posts

    Posted 13 Jul Link to this post

    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 visualization (charts) and form elements.
Back to Top