abandonRows() not working in JS

  • 1
  • Question
  • Updated 2 years ago
  • Answered

This is weird. I have a abandonRows()  followed by model.save() in javascript. It seems to work from the UI. That is the table list is refreshed and from the console, it shows the data is removed. But it is actually not delete from the database. Is that correct?

Photo of jili@heidrick.com

jili@heidrick.com

  • 2,032 Points 2k badge 2x thumb

Posted 2 years ago

  • 1
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Hi Jili. Looking at our API documentation, abandonRows() will remove an array of rows from a model without requesting that that the rows be deleted from the database. It sounds like you're looking for the model.save() to save changes and delete the abandoned rows from the model. If that's what you're aiming for, I believe you would explicitly need to mark them for deletion, and then save the model changes. deleteRow() may be what you're after - I would suggest experimenting with this in a safe non-critical environment and checking the API documentation for usage details. Also, undeleteRow() may be good to know about, if you want to undo the action of marking the row for deletion.
(Edited)
Photo of jili@heidrick.com

jili@heidrick.com

  • 2,032 Points 2k badge 2x thumb
deleteRow() and model.save is the correct way to delete from database. Thanks.
Photo of jili@heidrick.com

jili@heidrick.com

  • 2,032 Points 2k badge 2x thumb
Thanks! Yes I read the documentation around that. It says it's best to use abandonRows() for multiple rows. And call mod l.save after that to commit to the database. I did that but it's not committing the deletion.


Are you saying I should call markrowfordeletion, deleteRow() then call save?
(Edited)
Photo of Kvin Cloud

Kvin Cloud

  • 262 Points 250 badge 2x thumb
Hello Jili,

AbandonRows() - will empty your model, meaning it will sweep off all data including Id's of records in model, in order to delete records from database, we need to supply Ids.
 
Try as shown below:

var $ = skuid.$;

$.each(myModel.getRows(), function(){    
      myModel.deleteRow(this);
});

myModel.save();


Hope this helps!
Photo of jili@heidrick.com

jili@heidrick.com

  • 2,032 Points 2k badge 2x thumb
Using deleteRow instead of abandonRows worked. Thanks!