saveChanges() and manual sync() trigger duplicate destroy call

1 Answer 474 Views
Data Source Grid
Lynn
Top achievements
Rank 1
Iron
Lynn asked on 20 Sep 2021, 12:25 PM

Using a "destroy" command in the datagrid and "autoSync: false", it somehow calls the "destroy" twice. Any idea if I'm doing something wrong? When I set autoSync to true, it only fires once.

The following config gives me:

destroy
destroy
success
success
destroy: (options) => {
    console.log("destroy");
    $.ajax({
        url: $discountProductsGrid.data("delete-url"),
        dataType: "json",
        contentType: 'application/json',
        type: "POST",
        data: kendo.stringify({
            discountNumber: options.data.discountNumber,
            productNumber: options.data.productNumber,
            productColorId: options.data.productColorId,
            productSizeId: options.data.productSizeId,
        }),
        success: (result) => {
            console.log("success");
            options.success(result);
        },
        error: (result) => {
            console.log("error");
            options.error(result);
        },
    });
},

I do have sorting, filtering, and paging on the server, though I don't expect that to matter.

My model isn't very complicated and I've verified that there are no double IDs. At first I was thinking that perhaps the response body was incorrect, but that shouldn't be a problem because it fires the same destroy twice and doesn't wait for the first destroy to finish.

kendo.data.Model.define({
    id: "discountLineId",
    fields: {
        discountLineId: {type: "string"},
        discountNumber: {type: "number"},
        productSupplierName: {type: "string"},
        productCategoryDescription: {type: "string"},
        productNumber: {type: "number"},
        productId: {type: "string"},
        productDescription: {type: "string"},
        productColorId: {type: "string"},
        productColorDescription: {type: "string"},
        productSizeId: {type: "string", nullable: true},
        productSizeDescription: {type: "string", nullable: true},
        discountSalesPrice: {type: "number"},
        productSalesPrice: {type: "number"},
        discountSalesPricePercentage: {type: "number"},
    }
})
The method I use for saving:
$discountLineGrid.on("click", ".k-grid-save-changes", (e) => {
    e.preventDefault();

    discountLineGrid.saveChanges();

    // sync also firesd 
    // discountLineDataSource.sync();
});

I've verified inside the data source (in the range part), that the data is only 19 and that only the one record is that has to be deleted is still in the prestine data or whatever that is.

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 23 Sep 2021, 11:57 AM

Hello, Lynn,

The behavior is expected when autoSync is set to true. Please go through this forum thread for further information on the issue. If that is not what is causing the behavior, please provide a small runnable example where I can observe the problem.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Data Source Grid
Asked by
Lynn
Top achievements
Rank 1
Iron
Answers by
Martin
Telerik team
Share this question
or