Search code examples
tabulator

how to Cancel Edit in tabulator


after editing data in any row how to allow the user to cancel the edited data to go back to original data , cannot reload the whole table as this will cancel all edited rows , i only need to cancel one row
the undo function "table.undo();" need to be called many times to undo the whole row ,is there some thing like "row.undo();" i would like to code to look something like blow

 var ivInvGRNDGrid = new Tabulator("#ivInvGRNDGrid", {
                ajaxURL: "/abc/abcd/GetData",
                layout: "fitColumns",
                 index: "id",
                columns: [
                    { title: "Delete", formatter: DeleteIcon, width: 40, align: "center", cellClick: function (e, cell) { ivInvGRNDDelete(cell.getRow().getData().id); }, headerSort: false   },

{ title: "Cancel Edit", formatter: UndoIcon, width: 40, align: "center", cellClick: function (e, cell) { row.undo(); }, headerSort: false  },
                    { id: "ID", title: "@Localizer["ID"]", field: "iD", headerToolTip: "@Localizer["IDtip"]", validator: "required", editor: "number", visible: false, sorter: "number", editable: Editable },
                    { id: "ItemID", title: "@Localizer["ItemID"]", field: "itemID", headerToolTip: "@Localizer["ItemIDtip"]", validator: "required", editor: "number", validator: "required", minWidth: 120, editable: Editable },


                ],

            });

Solution

  • There is no row undo function i'm afraid, but you can restore the previous value of a cell by calling the restoreOldValue on the cell component. so in the cellClick function on your cancel edit row you could do something like this:

    function(e, cell){
        cell.getRow().getCells().forEach(function(cell){
            var oldVal = cell.getOldValue();
    
            if(oldVal !== null){
                cell.restoreOldValue();
            }
        })
    }