Delete All Rows Past Index

It seems that grid.getRowsNum() doesn’t update after the first delete.
difference is the number of rows I want to delete from the end of the grid.

function removeDistributionRows(grid,difference) { for (var ind=0;ind<difference;ind+=1) { grid.deleteRow(grid.getRowId(grid.getRowsNum()-1)); } }

I tried modifying it with an increasing index but it still doesn’t work. Has anyone had any success with a similar problem?

I also tried using grid.forEachRow() but it didn’t grab all the rows and they didn’t seem to be in order

Solved, it turns out the ids weren’t set properly