Skip to content

Row Selection

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.

Selected rows
Source code
import { defineCustomElements } from '@revolist/revogrid/loader';
defineCustomElements();
import { useRandomData, currentTheme } from '../composables/useRandomData';
const { createRandomData } = useRandomData();
const { isDark } = currentTheme();
import {
AdvanceFilterPlugin,
ColumnStretchPlugin,
RowOddPlugin,
RowSelectPlugin,
} from '@revolist/revogrid-pro';
const grid = document.querySelector('revo-grid');
if (grid) {
grid.source = createRandomData(100);
// Define columns
grid.columns = [
{
name: '🍎 Fruit',
prop: 'name',
sortable: true,
rowSelect: true,
filter: ['selection'],
},
];
// Define plugin
grid.plugins = [RowOddPlugin, RowSelectPlugin, AdvanceFilterPlugin, ColumnStretchPlugin];
grid.additionalData = {
stretch: 'all'
};
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:

  1. Using rowSelect Prop in Columns
  2. Using columnType with RowSelectColumnType

Option 1: Using rowSelect Prop in Columns

In this approach, the rowSelect property in the column definition enables checkbox-based row selection for the specific column.

grid.columns = [
{
prop: '_check',
rowSelect: true,
},
...
];
// Define plugin
grid.plugins = [RowSelectPlugin];

Option 2: Using columnType with RowSelectColumnType

Alternatively, you can use a custom columnType and the RowSelectColumnType to enable row selection.

import { RowSelectColumnType, RowSelectPlugin, DEFAULT_SEL_PROP } from '@revolist/revogrid-pro';
grid.source = [];
// Define columns
grid.columns = [{
prop: DEFAULT_SEL_PROP,
columnType: 'select' // Use columnType 'select'
}, ...];
// Define plugin
grid.plugins = [RowSelectPlugin];
// Define the custom column type for selection
grid.columnTypes = { select: new RowSelectColumnType()};