Skip to content

Commit

Permalink
fix: 🐛 update the index accordingly when modifying existing rows
Browse files Browse the repository at this point in the history
  • Loading branch information
moeyang13 authored and mportuga committed Aug 15, 2023
1 parent 45fd6a2 commit 945d4f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/js/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,9 @@ angular.module('ui.grid')
if ( oldRow ) {
newRow = oldRow;
newRow.entity = newEntity;
if (newRow.index !== i) {
newRow.index = i;
}
}

// if we didn't find the row, it must be new, so create it
Expand Down
12 changes: 12 additions & 0 deletions packages/core/test/core/factories/Grid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,18 @@ describe('Grid factory', function() {
expect(grid.rows[1].entity.str).toBe('xyz');
expect(grid.rows[2].entity.str).toBe('bac');
});

it('should delete and insert new in the middle', function() {
dataRows.splice(2, 0, {str: 'wwe'});
grid.modifyRows(dataRows);

expect(grid.getRow).not.toHaveBeenCalled();
expect(grid.rows.length).toBe(4);
expect(grid.rows[0].index).toBe(0);
expect(grid.rows[2].entity.str).toBe('wwe');
expect(grid.rows[3].entity.str).toBe('bac');
expect(grid.rows[3].index).toBe(3);
});
});

describe('binding', function() {
Expand Down

0 comments on commit 945d4f8

Please sign in to comment.