undo on DataCollection

const records = new webix.DataCollection({
    url: "/api/records",
    save: {
        updateFromResponse: true,
        url: "/api/records"
    }
});
records.add({}); // API THROWS ERROR
records.serialize()

My problem is when api throws an error, I can see the non-added record is still in datacollection.

Is there any way to prevent this behaviour?

Comments

  • edited April 13

    const records = new webix.DataCollection({
    url: "records",
    save: {
    updateFromResponse: true,
    url: "records",
    on: {
    onBeforeSaveError(id, status, obj, details) {
    this.ignore(() => {
    if (status == "insert") {
    records.remove(id);
    } else if (status == "update") {
    //records.update(id, olddata);
    }
    });

            }
        }
    }
    

    });
    export default records;

    I wrote a solution for insert operation but I cannot do it for update and delete. I need the data before the operation.

    Maybe it is good idea to implement webix.Undo to datacollection?

    What do you think?

  • webix.DataCollectionU = webix.proto({
    }, webix.DataCollection, webix.Undo);

    That solved my problem

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion