angular-ui/ui-grid

saveState's restore function references an outdated visibleRowCache when sort has been performed

Open

#5,312 创建于 2016年4月12日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)JavaScript (5,395 star) (2,496 fork)batch import
good first issue

描述

In saveState.js, the restore function references an outdated version of visibleRowCache when sort has been performed.

If the user has previously saved the state of the grid, and then sorts the data in a different order, the visibleRowCache will then be updated. This happens as the grid is refreshed whenever Grid.prototype.refresh calls setVisibleRows, which then updates the visibleRowCache.

Then, if they choose to restore the grid, the restore function first calls restoreColumns, which will update the sort of each column but doesn't touch the visibleRowCache.

Now, the restore function continues to restore other parts of the grid, but the grid has not refreshed at this point (it is not called until the end of the function), so visibleRowCache still has the previous sort.

This affects later calls, like restoreSelection when an identity function is not used to determine the selected row, since it calls selectRowByVisibleIndex and selectRowByVisibleIndex uses visibleRowCache to determine which rows should be selected.

One way I can think to update the visibleRowCache would be to refresh the grid after restoreColumns and only then continue restoring other parts of the grid.


This can be reproduced on the Save State example/plunkr: http://ui-grid.info/docs/#/tutorial/208_save_state Steps to recreate:

  1. Sort by Name (asc)
  2. Select the first row (Alexander Foley)
  3. Click Save
  4. Sort by Name (desc). Note the selected row is now the last row (Alexander Foley)
  5. Click Restore. Note the selected row is still the last row (Yvonne Parsons) and not the first row (Alexander Foley)

贡献者指南