Apply selection to rows in grid.
This is an advanced feature that allows users to select multiple rows in grid and explains how to implementthis with the help of the RowSelectPlugin
.
Source code import { defineCustomElements } from ' @revolist/revogrid/loader ' ;
import { useRandomData, currentTheme } from ' ../composables/useRandomData ' ;
const { createRandomData } = useRandomData ();
const { isDark } = currentTheme ();
} from ' @revolist/revogrid-pro ' ;
const grid = document. querySelector ( ' revo-grid ' );
grid.source = createRandomData ( 100 );
grid.plugins = [RowOddPlugin, RowSelectPlugin, AdvanceFilterPlugin, ColumnStretchPlugin];
grid.theme = isDark () ? ' darkCompact ' : ' compact ' ;
document. getElementById ( ' selected-rows ' )?. setHTMLUnsafe ( `100/0` );
grid. addEventListener ( ' rowselected ' , ( event ) => {
document. getElementById ( ' selected-rows ' )?. setHTMLUnsafe (
`Visible: ${ event . detail . visibleRowsCount } / ${ event . detail . visibleCount } , All: ${ event . detail . allRowsCount } / ${ event . detail . count } `
Key Features
Row Selection : Allows users to select multiple rows in the grid.
Column Selection : Enables users to select entire columns.
Automatic Theme Support : The plugin adapts to light or dark themes based on user settings.
Flexible and Extensible : This plugin demonstrates the potential for creating custom plugins, encouraging developers to expand the grid’s functionality further.
To enable the RowSelectPlugin
in your RevoGrid setup, you have two options:
Using rowSelect
Prop in Columns
Using columnType
with RowSelectColumnType
In this approach, the rowSelect property in the column definition enables checkbox-based row selection for the specific column.
grid.plugins = [RowSelectPlugin];
Alternatively, you can use a custom columnType and the RowSelectColumnType to enable row selection.
import { RowSelectColumnType, RowSelectPlugin, DEFAULT_SEL_PROP } from ' @revolist/revogrid-pro ' ;
columnType : ' select ' // Use columnType 'select'
grid.plugins = [RowSelectPlugin];
// Define the custom column type for selection
grid.columnTypes = { select : new RowSelectColumnType ()};