The RevSelection class, which manages selection logic for a grid component.
Main responsibilities
Selection Representation: Selections are stored as rectangles, rows, and columns for efficient memory usage and quick checks.
Selection Operations: Provides methods to select, deselect, and toggle selection for cells, rows, columns, and rectangular areas. Supports single and multiple selection areas.
Area Types: Handles different selection area types (all, rectangle, row, column) and tracks the last selected area.
Focus Linking: Integrates with the grid's focus system to clear selection when focus changes, if linked.
Change Management: Batches selection changes to minimize event firing and supports silent changes.
Stashing/Restoring: Can stash and restore selection state, including selected rows and columns, for filtering and sorting scenarios.
Selection Queries: Provides methods to check if a cell, row, or column is selected, and to get the type of selection covering a cell.
Grid Changes: Adjusts selection state when rows or columns are inserted, deleted, or moved.
Events: Exposes event hooks for notifying when selection changes.
Selection areas
A selection consists of one or more selection areas. There are 4 types of selection areas enumerated by RevSelectionAreaTypeId.
dynamicAll: All the cells within a selection's subgrid. The size of this area will dynamically adjust if rows or columns are added or deleted.
rectangle: A rectangle of cells within the selection's subgrid.
row: One or more contiguous rows within the selection's subgrid.
column: One or more contiguous columns. This is independent of the selection's subgrid.
Selection areas can be in different subgrids however individual areas of type dynamicAll, rectangle, row are fully contained within one subgrid.
If multiple changes are made to a selection, it is recommended to wrap these with calls to beginChange() and endChange(). This will reduce the number of times the grid needs to be rendered.
Stash and restore
When sorting or filtering a grid, the location of cells within selection areas may change. To ensure that the same cells remain selected after the sort or filter operation, a stash of the selection is created prior to the operation and then the selection from the stash is restored after the operation.
The stash contains a representation of the selection areas which is not affected by the sort or filter operation.
For column areas, the column field names are used.
For rows, if the RevDataServergetRowIdFromIndex() function exists, it is used to get an Id for a row which is not affected by filtering or sorting. If getRowIdFromIndex() is not implemented, row selection areas will not be included in the stash and be discarded. When restoring rows from a stash, the getRowIndexFromId() function will be used if it is implemented. Otherwise, the getRowIdFromIndex() will be used however this is not as efficient.
Only the cell at the first point of the last Rectangle added to a selection will be included in the stash.