how to find the rows selected for deletion in a table.

  • 1
  • Question
  • Updated 2 years ago
  • Answered
I am overriding the skuid standard save button. So how can I find the row selected for deletion in a table. Is there a way to find the mode of the deleted rows? Once I find this, i believe  skuid.model.getModel('SalesCallModel').save(); will take care of delete too, correct?
Photo of Pavithra

Pavithra

  • 180 Points 100 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Official Response
You can easily get a list of which rows in a Model that are edited, deleted, and/or newly-created using Skuid's Model object API's. Note: these categories are NOT mutually exclusive --- for instance, rows that have been marked for deletion are considered "changed", as are newly-created rows, but you can mix and match the appropriate API methods as needed.

Here are the key Model API methods that are relevant:

  • isRowChanged(row) --- returns newly-created or edited rows, as well as rows marked for deletion
  • isRowNew(row) --- returns newly-created rows that have never been saved to the server
  • isRowMarkedForDeletion(row) --- returns rows that have been marked for deletion\
There are other methods that may be useful, so see the Model object docs for more details.

var model = skuid.$M('SalesCallModel');

var changedRows = model.getRows().filter(function(row){
    return model.isRowChanged(row);
});

var rowsMarkedForDeletion = model.getRows().filter(function(row){
    return model.isRowMarkedForDeletion(row);
});

var newlyCreatedRows = model.getRows().filter(function(row){
    return model.isRowNew(row);
});

var changedRowsExcludingRowsMarkedForDeletion = model.getRows().filter(function(row){
    return model.isRowChanged(row) && !model.isRowMarkedForDeletion(row);
});