2

I want to how can we undo the specific being added in the grid before actually saving it .

Please have a look at this Picture

I 've added two rows but since for eg: for some validations failures the second row is not valid so I want to undo the second row but keeping the first dirty for the saving of that data to the db.

What i was trying is I was pushing all the dirty rows to an array and then updating in the database. But I don't know how to undo or delete the invalid row being added. Without reloading the grid Example for reference Live example

  • The reference example is working ? So I don't understand what you need ? What is wrong with the example ? – pagep Mar 30 '17 at 08:16

1 Answers1

1

You shouldn't have to push the rows into an array for synchronization. What you really want to use is the methods available on the underlying store and/or model.

To reject the second model and update all other ones in the database, two lines suffice. The exact code may differ depending on the Ext version; in ExtJS 6.2.1, it would be:

grid.getStore().getAt(1).reject() (or .drop())
grid.getStore().sync()

while the generalized approach would be to reject all invalid models:

var store = grid.getStore(),
    invalidRecords = store.query(function(record) {
        return !record.getValidation().isValid();
    });
invalidRecords.each(function(record) {
     record.reject();
})
store.sync();
Alexander
  • 18,932
  • 15
  • 54
  • 138
  • How to go back to grid, like the `Processing.... Please Wait` bar is forever appearing –  Mar 30 '17 at 10:24
  • 1
    Data gets added to the grid only when reloaded the data will not be there, So that shouldn't happen.... I don't have to save the data now, Scenario is When I click create record.. after I have created one record already, But I didn't save that yet. i'm creating the second record.. But for some reason it doesn't pass the validation so that record should get deleted.. but the first record should be present for saving in the dirty flag state... –  Mar 30 '17 at 11:48
  • 2
    `grid.getStore().remove(grid.getStore().getAt(1))` removes the second record from the store. – Alexander Mar 30 '17 at 12:59
  • 1
    here we are defining the row index.. what if the row index is varying.. how to get the current row index.. Alexander?? –  Mar 30 '17 at 14:03