Row Selection
index
Description
For row selection, you can simply play with couple of grid options (see below) and subscribe to onSelectedRowsChanged (a SlickGrid Event that is, it's not an Observable). However please note that onSelectedRowsChanged is a function available on the Grid object and you will need bind to (gridChanged) to get the object when grid is ready. There are 2 types of row selection(s) which you can do.
Note: enableCheckboxSelector and enableExcelCopyBuffer do not work well together, this is because they both share the same Row.SelectionModel and one cancels the other. It is recommended to not use enableExcelCopyBuffer in that case.
Demo
Single Row Selection
For a single row selection, you need to have enableCellNavigation: true, enableRowSelection: true and multiSelect: false and as described earlier, subscribe to onSelectedRowsChanged (for that you need to bind to (gridChanged)).
Note: if you want to change from Multiple Selections to Single Selection (and vice-versa), you could use the grid options enableCellNavigation flag, however this is not possible when using Inline Editors since this flag is required. However, there is no other known ways of toggling dynamically.
View
Component
Multiple Row Selections
As for multiple row selections, you need to provide an extra grid option of rowSelectionOptions which is an object and within it, you need to disable the selectActiveRow flag. The other configurations are the same as a Single Selection, which is to enable enableCheckboxSelector and enableRowSelection. Then as describe earlier, you will subscribe to onSelectedRowsChanged (for that you need to bind to (gridChanged)).
View
Component
Changing Dynamically from Single to Multiple Selections (and vice-versa)
If you want to change from Multiple Selections to Single Selection (and vice-versa), you could toggle the grid options enableCellNavigation flag (False when you want Single Selection), however this is not possible when using Inline Editors since this flag is required. Note that there is currently no other ways of toggling dynamically without re-creating the grid.
Mixing Single & Multiple Row Selections
SlickGrid is so powerful and customizable, you could if you wish mix the multiple row selections (cell column 1) and single row selection (any other cell click). For that though, you will need to use 2 SlickGrid Events (onClick and onSelectedRowsChanged). For example we can do it this way:
View
Component
Disable Custom Rows Selections via selectableOverride
selectableOverrideYou can use selectableOverride to provide custom logic to disable certain rows selections, for example the code below will remove the row selection on every second row.
Component
Disable External Button when having Empty Selection
When having an external button that you want to work only when there's row selection, there are 2 ways of doing this.
use the
onSelectedRowsChangedevent (via your View in HTML or via ViewModel)
use the
onGridStateChangedevent (see Grid State & Presets Wiki)
Change Row Selections
You can change which row(s) are selected by using the built-in SlickGrid method setSelectedRows(rowIndexes) (passing an empty array will clear all selection), however please note that it requires an array of row indexes as you see them in the UI and it won't work that great with Pagination (if that is what you are looking for then take a look at this Stack Overflow Q&A)
Hybrid Selection Model
Starting with v9.10.0, you can now use the new Hybrid Selection Model, this new model will allow you to do Cell Selection & Row Selection in the same grid. This wasn't previously doable before that version because SlickGrid only ever allows 1 selection model to be loaded at once and so we had to load either SlickCellSelectionModel or SlickRowSelectionModel but never both of them at the same time. The new Hybrid Selection Model is merging both of these plugins in a single plugin allowing us to do both type of selections.
[!NOTE] You can use
enableHybridSelection: truegrid option to enable the new Hybrid Model, this new model will eventually replace both cell/row selection model in the future since there's no need to keep all these models when only 1 is more than enough
For example, we could use the Excel Copy Buffer (Cell Selection) and use rowSelectColumnIds (Row Selection)
Hybrid Selection Model and Drag-Fill
You can also onDragReplaceCells event to drag and fill cell values to the extended cell selection.
View
Component
Troubleshooting
Adding a Column dynamically is removing the Row Selection, why is that?
The reason is because the Row Selection (checkbox) plugin is a special column and Angular-Slickgrid is adding an extra column dynamically for the Row Selection checkbox and that is not reflected in your local copy of columnDefinitions. To address this issue, you need to get the Angular-Slickgrid internal copy of all columns (including the extra columns), you can get it via getAllColumnDefinitions() from the Grid Service and then you can use to that array and that will work.
Last updated