Documentation
Row Selection
Select one or many rows with checkboxes, click-to-select, keyboard, or the TableAPI.
- 1
Enable checkbox selection
SetenableRowSelectionfor a pinned checkbox column (multiple mode by default, with select-all in the header). ProvidegetRowIdso selection survives sort, filter, and pagination.React TSXCopy<SimpleTableenableRowSelectioncolumns={columns}rows={rows}getRowId={({ row }) => String(row.id)}/>Vue SFCCopy<SimpleTable:columns="columns":rows="rows":enable-row-selection="true":get-row-id="(ctx) => String(ctx.row.id)"/>AngularCopy<simple-table[columns]="columns"[rows]="rows"[enableRowSelection]="true"[getRowId]="getRowId"></simple-table>SvelteCopy<SimpleTable{columns}{rows}enableRowSelection={true}getRowId={({ row }) => String(row.id)}/>Solid TSXCopy<SimpleTableenableRowSelectioncolumns={columns}rows={rows()}getRowId={({ row }) => String(row.id)}/>TypeScriptCopynew SimpleTableVanilla(container, {columns,rows,enableRowSelection: true,getRowId: ({ row }) => String(row.id),}); - 2
Handle selection changes
UseonRowSelectionChangefor updates, or read selected rows from the table ref withgetSelectedRowsData().React TSXCopy<SimpleTableenableRowSelectioncolumns={columns}rows={rows}getRowId={({ row }) => String(row.id)}onRowSelectionChange={({ row, isSelected, selectedRows }) => {// ...}}/>Vue SFCCopy<SimpleTable:columns="columns":rows="rows":enable-row-selection="true":get-row-id="(ctx) => String(ctx.row.id)":on-row-selection-change="handleRowSelectionChange"/>AngularCopy<simple-table[columns]="columns"[rows]="rows"[enableRowSelection]="true"[getRowId]="getRowId"[onRowSelectionChange]="handleRowSelectionChange"></simple-table>SvelteCopy<SimpleTable{columns}{rows}enableRowSelection={true}getRowId={({ row }) => String(row.id)}onRowSelectionChange={handleRowSelectionChange}/>Solid TSXCopy<SimpleTableenableRowSelectioncolumns={columns}rows={rows()}getRowId={({ row }) => String(row.id)}onRowSelectionChange={({ row, isSelected, selectedRows }) => {// ...}}/>TypeScriptCopynew SimpleTableVanilla(container, {columns,rows,enableRowSelection: true,getRowId: ({ row }) => String(row.id),onRowSelectionChange: ({ row, isSelected, selectedRows }) => {// ...},});
Patterns
Single selection
Set rowSelectionMode="single" when only one row should be selected. Selecting another row replaces the previous selection; the header select-all control is hidden.
React TSX
Copy
<SimpleTableenableRowSelectioncolumns={columns}rows={rows}rowSelectionMode="single"getRowId={({ row }) => String(row.id)}/>
Vue SFC
Copy
<SimpleTable:columns="columns":rows="rows":enable-row-selection="true"row-selection-mode="single":get-row-id="(ctx) => String(ctx.row.id)"/>
Angular
Copy
<simple-table[columns]="columns"[rows]="rows"[enableRowSelection]="true"rowSelectionMode="single"[getRowId]="getRowId"></simple-table>
Svelte
Copy
<SimpleTable{columns}{rows}enableRowSelection={true}rowSelectionMode="single"getRowId={({ row }) => String(row.id)}/>
Solid TSX
Copy
<SimpleTableenableRowSelectioncolumns={columns}rows={rows()}rowSelectionMode="single"getRowId={({ row }) => String(row.id)}/>
TypeScript
Copy
new SimpleTableVanilla(container, {columns,rows,enableRowSelection: true,rowSelectionMode: "single",getRowId: ({ row }) => String(row.id),});
Click to select
Use selectRowOnClick, hide the checkbox column with showRowSelectionColumn={false}, and set selectableCells={false} so clicks (and keyboard Space / arrows) drive row selection.
React TSX
Copy
<SimpleTableenableRowSelectioncolumns={columns}rows={rows}selectRowOnClickshowRowSelectionColumn={false}selectableCells={false}getRowId={({ row }) => String(row.id)}/>
Vue SFC
Copy
<SimpleTable:columns="columns":rows="rows":enable-row-selection="true":select-row-on-click="true":show-row-selection-column="false":selectable-cells="false":get-row-id="(ctx) => String(ctx.row.id)"/>
Angular
Copy
<simple-table[columns]="columns"[rows]="rows"[enableRowSelection]="true"[selectRowOnClick]="true"[showRowSelectionColumn]="false"[selectableCells]="false"[getRowId]="getRowId"></simple-table>
Svelte
Copy
<SimpleTable{columns}{rows}enableRowSelection={true}selectRowOnClick={true}showRowSelectionColumn={false}selectableCells={false}getRowId={({ row }) => String(row.id)}/>
Solid TSX
Copy
<SimpleTableenableRowSelectioncolumns={columns}rows={rows()}selectRowOnClickshowRowSelectionColumn={false}selectableCells={false}getRowId={({ row }) => String(row.id)}/>
TypeScript
Copy
new SimpleTableVanilla(container, {columns,rows,enableRowSelection: true,selectRowOnClick: true,showRowSelectionColumn: false,selectableCells: false,getRowId: ({ row }) => String(row.id),});
Programmatic selection
Call selectRow, toggleRowSelection, getSelectedRowsData, and clearRowSelection on the table API. See also Programmatic Control.
React TSX
Copy
tableRef.current?.selectRow("1", true);tableRef.current?.toggleRowSelection("2");const selected = tableRef.current?.getSelectedRowsData();tableRef.current?.clearRowSelection();
Vue SFC
Copy
tableRef.value?.selectRow("1", true);tableRef.value?.toggleRowSelection("2");const selected = tableRef.value?.getSelectedRowsData();tableRef.value?.clearRowSelection();
Angular
Copy
this.tableRef.getAPI()?.selectRow("1", true);this.tableRef.getAPI()?.toggleRowSelection("2");const selected = this.tableRef.getAPI()?.getSelectedRowsData();this.tableRef.getAPI()?.clearRowSelection();
Svelte
Copy
tableRef.getAPI()?.selectRow("1", true);tableRef.getAPI()?.toggleRowSelection("2");const selected = tableRef.getAPI()?.getSelectedRowsData();tableRef.getAPI()?.clearRowSelection();
Solid TSX
Copy
tableRef.selectRow("1", true);tableRef.toggleRowSelection("2");const selected = tableRef.getSelectedRowsData();tableRef.clearRowSelection();
TypeScript
Copy
table.selectRow("1", true);table.toggleRowSelection("2");const selected = table.getSelectedRowsData();table.clearRowSelection();
Checkbox selection example
Library Management Demo
• Click the header checkbox to select/deselect all books
• Click individual row checkboxes to select specific books
Selected Books:None
React TSX
Copy
1import { useState, useMemo } from "react";2import { SimpleTable } from "@simple-table/react";3import type {4 Theme,5 ReactColumnDef,6 CellRendererProps,7 RowSelectionChangeProps,8} from "@simple-table/react";9import { rowSelectionConfig, rowSelectionData } from "./row-selection.demo-data";10import type { LibraryBook } from "./row-selection.demo-data";11import "@simple-table/react/styles.css";1213const RowSelectionDemo = ({14 height = "348px",15 theme,16}: {17 height?: string | number;18 theme?: Theme;19}) => {20 const [selectedBooks, setSelectedBooks] = useState<LibraryBook[]>([]);2122 const headers: ReactColumnDef[] = useMemo(23 () =>24 rowSelectionConfig.headers.map((h) => {25 if (h.accessor === "status") {26 return {27 ...h,28 cellRenderer: ({ row }: CellRendererProps) => {29 const s = String(row.status);30 const color =31 s === "Available" ? "#16a34a" : s === "Checked Out" ? "#ea580c" : "#dc2626";32 return <span style={{ color, fontWeight: "bold" }}>{s}</span>;33 },34 };35 }36 return h;37 }),38 [],39 );4041 const handleRowSelectionChange = (props: RowSelectionChangeProps) => {42 const selected = rowSelectionData.filter((book) => props.selectedRows.has(String(book.id)));43 setSelectedBooks(selected);44 };4546 return (47 <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>48 <div49 style={{50 padding: 12,51 backgroundColor: "#f0f9ff",52 borderRadius: 8,53 border: "1px solid #bae6fd",54 }}55 >56 <div style={{ fontWeight: "bold", marginBottom: 4, color: "#0c4a6e" }}>57 Library Management Demo58 </div>59 <div style={{ fontSize: 13, color: "#475569", marginBottom: 6 }}>60 Use the checkbox column to select books for checkout or bulk actions.61 </div>62 <div style={{ fontSize: 13, color: "#334155" }}>63 <strong>Selected Books: </strong>64 {selectedBooks.length > 0 ? selectedBooks.map((b) => b.title).join(", ") : "None"}65 </div>66 </div>6768 <SimpleTable69 columns={headers}70 rows={rowSelectionConfig.rows}71 enableRowSelection72 columnResizing73 columnReordering74 selectableCells75 onRowSelectionChange={handleRowSelectionChange}76 height={height}77 theme={theme}78 />79 </div>80 );81};8283export default RowSelectionDemo;
Vue SFC
Copy
1<script setup lang="ts">2import { ref, computed } from "vue";3import { SimpleTable } from "@simple-table/vue";4import type { Theme, RowSelectionChangeProps, VueColumnDef } from "@simple-table/vue";5import { rowSelectionConfig, rowSelectionData } from "./row-selection.demo-data";6import type { LibraryBook } from "./row-selection.demo-data";7import "@simple-table/vue/styles.css";89withDefaults(defineProps<{ height?: string | number; theme?: Theme }>(), {10 height: "348px",11});1213const selectedBooks = ref<LibraryBook[]>([]);1415const selectedTitles = computed(() =>16 selectedBooks.value.length > 017 ? selectedBooks.value.map((b) => b.title).join(", ")18 : "None",19);2021const headers: VueColumnDef[] = rowSelectionConfig.headers.map((h) => {22 if (h.accessor === "status") {23 return {24 ...h,25 cellRenderer: ({ row }: { row: Record<string, unknown> }) => {26 const s = String(row.status);27 const color = s === "Available" ? "#16a34a" : s === "Checked Out" ? "#ea580c" : "#dc2626";28 return `<span style="color:${color};font-weight:bold">${s}</span>`;29 },30 };31 }32 return { ...h };33});3435function handleRowSelectionChange(props: RowSelectionChangeProps) {36 selectedBooks.value = rowSelectionData.filter((book) =>37 props.selectedRows.has(String(book.id)),38 );39}40</script>4142<template>43 <div style="display: flex; flex-direction: column; gap: 12px">44 <div45 style="padding: 12px; background-color: #f0f9ff; border-radius: 8px; border: 1px solid #bae6fd"46 >47 <div style="font-weight: bold; margin-bottom: 4px; color: #0c4a6e">48 Library Management Demo49 </div>50 <div style="font-size: 13px; color: #475569; margin-bottom: 6px">51 Click rows to select books. Use the checkbox column to select multiple.52 </div>53 <div style="font-size: 13px; color: #334155">54 <strong>Selected Books: </strong>{{ selectedTitles }}55 </div>56 </div>5758 <SimpleTable59 :columns="headers"60 :rows="rowSelectionConfig.rows"61 :enable-row-selection="true"62 :column-resizing="true"63 :column-reordering="true"64 :selectable-cells="true"65 :height="height"66 :theme="theme"67 @row-selection-change="handleRowSelectionChange"68 />69 </div>70</template>
Angularrow-selection-demo.component.ts
Copy
1import { Component, Input } from "@angular/core";2import {SimpleTableComponent} from "@simple-table/angular";import type { AngularColumnDef, Row, RowSelectionChangeProps, Theme } from "@simple-table/angular";3import { rowSelectionConfig, rowSelectionData } from "./row-selection.demo-data";4import type { LibraryBook } from "./row-selection.demo-data";5import "@simple-table/angular/styles.css";67@Component({8 selector: "row-selection-demo",9 standalone: true,10 imports: [SimpleTableComponent],11 template: `12 <div style="display: flex; flex-direction: column; gap: 12px">13 <div style="padding: 12px; background-color: #f0f9ff; border-radius: 8px; border: 1px solid #bae6fd">14 <div style="font-weight: bold; margin-bottom: 4px; color: #0c4a6e">15 Library Management Demo16 </div>17 <div style="font-size: 13px; color: #475569; margin-bottom: 6px">18 Click rows to select books. Use the checkbox column to select multiple.19 </div>20 <div style="font-size: 13px; color: #334155">21 <strong>Selected Books: </strong>{{ selectedTitles }}22 </div>23 </div>2425 <simple-table26 [rows]="rows"27 [columns]="headers"28 [height]="height"29 [theme]="theme"30 [enableRowSelection]="true"31 [columnResizing]="true"32 [columnReordering]="true"33 [selectableCells]="true"34 [onRowSelectionChange]="handleSelectionChange"35 ></simple-table>36 </div>37 `,38})39export class RowSelectionDemoComponent {40 @Input() height: string | number = "348px";41 @Input() theme?: Theme;4243 readonly rows: Row[] = rowSelectionConfig.rows;44 readonly headers: AngularColumnDef[] = rowSelectionConfig.headers.map((h) => {45 if (h.accessor === "status") {46 return {47 ...h,48 cellRenderer: ({ row }: { row: Record<string, unknown> }) => {49 const s = String(row.status);50 const color = s === "Available" ? "#16a34a" : s === "Checked Out" ? "#ea580c" : "#dc2626";51 return `<span style="color:${color};font-weight:bold">${s}</span>`;52 },53 };54 }55 return { ...h };56 });5758 selectedBooks: LibraryBook[] = [];5960 get selectedTitles(): string {61 return this.selectedBooks.length > 062 ? this.selectedBooks.map((b) => b.title).join(", ")63 : "None";64 }6566 handleSelectionChange = (props: RowSelectionChangeProps): void => {67 this.selectedBooks = rowSelectionData.filter((book) =>68 props.selectedRows.has(String(book.id)),69 );70 };71}727374// row-selection.demo-data.ts75// Self-contained demo table setup for this example.76import type { AngularColumnDef } from "@simple-table/angular";777879export type LibraryBook = {80 id: number;81 isbn: string;82 title: string;83 author: string;84 genre: string;85 yearPublished: number;86 pages: number;87 rating: number;88 status: string;89 librarySection: string;90 borrowedBy?: string;91};9293export const rowSelectionData: LibraryBook[] = [94 { id: 1001, isbn: "978-0553418026", title: "The Quantum Chronicles", author: "Dr. Elena Vasquez", genre: "Science Fiction", yearPublished: 2019, pages: 324, rating: 4.7, status: "Available", librarySection: "Fiction A-L" },95 { id: 1002, isbn: "978-0316769488", title: "Digital Renaissance", author: "Marcus Chen", genre: "Technology", yearPublished: 2021, pages: 287, rating: 4.2, status: "Checked Out", librarySection: "Technology", borrowedBy: "Sarah Williams" },96 { id: 1003, isbn: "978-1400079179", title: "Echoes of Ancient Wisdom", author: "Prof. Amara Okafor", genre: "Philosophy", yearPublished: 2018, pages: 456, rating: 4.9, status: "Available", librarySection: "Philosophy" },97 { id: 1004, isbn: "978-0062315007", title: "The Midnight Observatory", author: "Luna Rodriguez", genre: "Mystery", yearPublished: 2020, pages: 298, rating: 4.4, status: "Reserved", librarySection: "Fiction M-Z" },98 { id: 1005, isbn: "978-0544003415", title: "Sustainable Architecture Now", author: "Kai Nakamura", genre: "Architecture", yearPublished: 2022, pages: 368, rating: 4.6, status: "Available", librarySection: "Architecture" },99 { id: 1006, isbn: "978-0147516466", title: "Neural Networks Simplified", author: "Dr. Priya Sharma", genre: "Computer Science", yearPublished: 2021, pages: 412, rating: 4.8, status: "Checked Out", librarySection: "Computer Science", borrowedBy: "Alex Thompson" },100 { id: 1007, isbn: "978-0547928227", title: "Culinary Traditions of the World", author: "Isabella Fontana", genre: "Cooking", yearPublished: 2019, pages: 276, rating: 4.3, status: "Available", librarySection: "Lifestyle" },101 { id: 1008, isbn: "978-0525509288", title: "The Biomimicry Revolution", author: "Dr. James Whitfield", genre: "Biology", yearPublished: 2020, pages: 345, rating: 4.5, status: "Available", librarySection: "Science" },102 { id: 1009, isbn: "978-0345391803", title: "Symphonies in Code", author: "Aria Blackwood", genre: "Programming", yearPublished: 2022, pages: 423, rating: 4.7, status: "Checked Out", librarySection: "Computer Science", borrowedBy: "Emma Davis" },103 { id: 1010, isbn: "978-0812988407", title: "Urban Gardens & Green Spaces", author: "Miguel Santos", genre: "Gardening", yearPublished: 2021, pages: 189, rating: 4.1, status: "Available", librarySection: "Lifestyle" },104 { id: 1011, isbn: "978-0374533557", title: "The Psychology of Innovation", author: "Dr. Rachel Kim", genre: "Psychology", yearPublished: 2019, pages: 312, rating: 4.6, status: "Reserved", librarySection: "Psychology" },105 { id: 1012, isbn: "978-0593229439", title: "Climate Solutions for Tomorrow", author: "Dr. Hassan Al-Rashid", genre: "Environmental Science", yearPublished: 2022, pages: 398, rating: 4.8, status: "Available", librarySection: "Science" },106];107108export const rowSelectionHeaders: AngularColumnDef[] = [109 { accessor: "id", label: "Book ID", width: 80, sortable: true, type: "number" },110 { accessor: "isbn", label: "ISBN", width: 120, sortable: true, type: "string" },111 { accessor: "title", label: "Title", minWidth: 150, width: "1fr", sortable: true, type: "string" },112 { accessor: "author", label: "Author", width: 140, sortable: true, type: "string" },113 { accessor: "genre", label: "Genre", width: 120, sortable: true, type: "string" },114 { accessor: "yearPublished", label: "Year", width: 80, sortable: true, type: "number" },115 { accessor: "pages", label: "Pages", width: 80, sortable: true, type: "number" },116 { accessor: "rating", label: "Rating", width: 80, sortable: true, type: "number" },117 { accessor: "status", label: "Status", width: 100, sortable: true, type: "string" },118 { accessor: "librarySection", label: "Section", width: 120, sortable: true, type: "string" },119];120121export const rowSelectionConfig = {122 headers: rowSelectionHeaders,123 rows: rowSelectionData,124 tableProps: {125 enableRowSelection: true,126 columnResizing: true,127 columnReordering: true,128 selectableCells: true,129 },130} as const;131
Svelte
Copy
1<script lang="ts">2 import { SimpleTable } from "@simple-table/svelte";3 import type { Theme, RowSelectionChangeProps, SvelteColumnDef } from "@simple-table/svelte";4 import { rowSelectionConfig, rowSelectionData } from "./row-selection.demo-data";5 import type { LibraryBook } from "./row-selection.demo-data";6 import "@simple-table/svelte/styles.css";78 let { height = "348px", theme }: { height?: string | number; theme?: Theme } = $props();910 let selectedBooks: LibraryBook[] = $state([]);1112 let selectedTitles = $derived(13 selectedBooks.length > 014 ? selectedBooks.map((b) => b.title).join(", ")15 : "None",16 );1718 const headers: SvelteColumnDef[] = rowSelectionConfig.headers.map((h) => {19 if (h.accessor === "status") {20 return {21 ...h,22 cellRenderer: ({ row }: { row: Record<string, unknown> }) => {23 const s = String(row.status);24 const color = s === "Available" ? "#16a34a" : s === "Checked Out" ? "#ea580c" : "#dc2626";25 return `<span style="color:${color};font-weight:bold">${s}</span>`;26 },27 };28 }29 return { ...h };30 });3132 function handleRowSelectionChange(props: RowSelectionChangeProps) {33 selectedBooks = rowSelectionData.filter((book) =>34 props.selectedRows.has(String(book.id)),35 );36 }37</script>3839<div style="display: flex; flex-direction: column; gap: 12px;">40 <div style="padding: 12px; background-color: #f0f9ff; border-radius: 8px; border: 1px solid #bae6fd;">41 <div style="font-weight: bold; margin-bottom: 4px; color: #0c4a6e;">42 Library Management Demo43 </div>44 <div style="font-size: 13px; color: #475569; margin-bottom: 6px;">45 Click rows to select books. Use the checkbox column to select multiple.46 </div>47 <div style="font-size: 13px; color: #334155;">48 <strong>Selected Books: </strong>{selectedTitles}49 </div>50 </div>5152 <SimpleTable53 columns={headers}54 rows={rowSelectionConfig.rows}55 enableRowSelection={true}56 columnResizing={true}57 columnReordering={true}58 selectableCells={true}59 onRowSelectionChange={handleRowSelectionChange}60 {height}61 {theme}62 />63</div>
Solid TSX
Copy
1import { createSignal, createMemo } from "solid-js";2import {SimpleTable} from "@simple-table/solid";import type {3 Theme,4 SolidColumnDef,5 CellRendererProps,6 RowSelectionChangeProps,7} from "@simple-table/solid";8import { rowSelectionConfig, rowSelectionData } from "./row-selection.demo-data";9import type { LibraryBook } from "./row-selection.demo-data";10import "@simple-table/solid/styles.css";1112export default function RowSelectionDemo(props: {13 height?: string | number;14 theme?: Theme;15}) {16 const [selectedBooks, setSelectedBooks] = createSignal<LibraryBook[]>([]);1718 const selectedTitles = createMemo(() => {19 const books = selectedBooks();20 return books.length > 0 ? books.map((b) => b.title).join(", ") : "None";21 });2223 const headers: SolidColumnDef[] = rowSelectionConfig.headers.map((h) => {24 if (h.accessor === "status") {25 return {26 ...h,27 cellRenderer: (cr: CellRendererProps) => {28 const s = String(cr.row.status);29 const color = s === "Available" ? "#16a34a" : s === "Checked Out" ? "#ea580c" : "#dc2626";30 return <span style={{ color, "font-weight": "bold" }}>{s}</span>;31 },32 };33 }34 return h;35 });3637 const handleSelectionChange = (selection: RowSelectionChangeProps) => {38 const selected = rowSelectionData.filter((book) =>39 selection.selectedRows.has(String(book.id)),40 );41 setSelectedBooks(selected);42 };4344 return (45 <div style={{ display: "flex", "flex-direction": "column", gap: "12px" }}>46 <div47 style={{48 padding: "12px",49 "background-color": "#f0f9ff",50 "border-radius": "8px",51 border: "1px solid #bae6fd",52 }}53 >54 <div style={{ "font-weight": "bold", "margin-bottom": "4px", color: "#0c4a6e" }}>55 Library Management Demo56 </div>57 <div style={{ "font-size": "13px", color: "#475569", "margin-bottom": "6px" }}>58 Click rows to select books. Use the checkbox column to select multiple.59 </div>60 <div style={{ "font-size": "13px", color: "#334155" }}>61 <strong>Selected Books: </strong>62 {selectedTitles()}63 </div>64 </div>6566 <SimpleTable67 columns={headers}68 rows={rowSelectionConfig.rows}69 height={props.height ?? "348px"}70 theme={props.theme}71 enableRowSelection={true}72 columnResizing={true}73 columnReordering={true}74 selectableCells={true}75 onRowSelectionChange={handleSelectionChange}76 />77 </div>78 );79}
TypeScriptRowSelectionDemo.ts
Copy
1import { SimpleTableVanilla } from "simple-table-core";2import type { Theme, ColumnDef } from "simple-table-core";3import { rowSelectionConfig, rowSelectionData } from "./row-selection.demo-data";4import type { LibraryBook } from "./row-selection.demo-data";5import "simple-table-core/styles.css";67export function renderRowSelectionDemo(8 container: HTMLElement,9 options?: { height?: string | number; theme?: Theme },10): SimpleTableVanilla {11 const wrapper = document.createElement("div");12 wrapper.style.cssText = "display:flex;flex-direction:column;gap:12px";1314 const infoPanel = document.createElement("div");15 infoPanel.style.cssText =16 "padding:12px;background-color:#f0f9ff;border-radius:8px;border:1px solid #bae6fd";17 infoPanel.innerHTML = `18 <div style="font-weight:bold;margin-bottom:4px;color:#0c4a6e">Library Management Demo</div>19 <div style="font-size:13px;color:#475569;margin-bottom:6px">Click rows to select books. Use the checkbox column to select multiple.</div>20 <div style="font-size:13px;color:#334155"><strong>Selected Books: </strong><span id="selected-titles">None</span></div>21 `;2223 const tableContainer = document.createElement("div");24 wrapper.appendChild(infoPanel);25 wrapper.appendChild(tableContainer);26 container.appendChild(wrapper);2728 const titlesSpan = infoPanel.querySelector("#selected-titles")!;2930 const headers: ColumnDef[] = rowSelectionConfig.headers.map((h) => {31 if (h.accessor === "status") {32 return {33 ...h,34 cellRenderer: ({ row }: { row: Record<string, unknown> }) => {35 const s = String(row.status);36 const color = s === "Available" ? "#16a34a" : s === "Checked Out" ? "#ea580c" : "#dc2626";37 return `<span style="color:${color};font-weight:bold">${s}</span>`;38 },39 };40 }41 return { ...h };42 });4344 const table = new SimpleTableVanilla(tableContainer, {45 columns: headers,46 rows: rowSelectionConfig.rows,47 height: options?.height ?? "348px",48 theme: options?.theme,49 enableRowSelection: true,50 columnResizing: true,51 columnReordering: true,52 selectableCells: true,53 onRowSelectionChange: (selection) => {54 const selected: LibraryBook[] = rowSelectionData.filter((book) =>55 selection.selectedRows.has(String(book.id)),56 );57 titlesSpan.textContent =58 selected.length > 0 ? selected.map((b) => b.title).join(", ") : "None";59 },60 });6162 return table;63}646566// row-selection.demo-data.ts67// Self-contained demo table setup for this example.68import type { ColumnDef } from "simple-table-core";697071export type LibraryBook = {72 id: number;73 isbn: string;74 title: string;75 author: string;76 genre: string;77 yearPublished: number;78 pages: number;79 rating: number;80 status: string;81 librarySection: string;82 borrowedBy?: string;83};8485export const rowSelectionData: LibraryBook[] = [86 { id: 1001, isbn: "978-0553418026", title: "The Quantum Chronicles", author: "Dr. Elena Vasquez", genre: "Science Fiction", yearPublished: 2019, pages: 324, rating: 4.7, status: "Available", librarySection: "Fiction A-L" },87 { id: 1002, isbn: "978-0316769488", title: "Digital Renaissance", author: "Marcus Chen", genre: "Technology", yearPublished: 2021, pages: 287, rating: 4.2, status: "Checked Out", librarySection: "Technology", borrowedBy: "Sarah Williams" },88 { id: 1003, isbn: "978-1400079179", title: "Echoes of Ancient Wisdom", author: "Prof. Amara Okafor", genre: "Philosophy", yearPublished: 2018, pages: 456, rating: 4.9, status: "Available", librarySection: "Philosophy" },89 { id: 1004, isbn: "978-0062315007", title: "The Midnight Observatory", author: "Luna Rodriguez", genre: "Mystery", yearPublished: 2020, pages: 298, rating: 4.4, status: "Reserved", librarySection: "Fiction M-Z" },90 { id: 1005, isbn: "978-0544003415", title: "Sustainable Architecture Now", author: "Kai Nakamura", genre: "Architecture", yearPublished: 2022, pages: 368, rating: 4.6, status: "Available", librarySection: "Architecture" },91 { id: 1006, isbn: "978-0147516466", title: "Neural Networks Simplified", author: "Dr. Priya Sharma", genre: "Computer Science", yearPublished: 2021, pages: 412, rating: 4.8, status: "Checked Out", librarySection: "Computer Science", borrowedBy: "Alex Thompson" },92 { id: 1007, isbn: "978-0547928227", title: "Culinary Traditions of the World", author: "Isabella Fontana", genre: "Cooking", yearPublished: 2019, pages: 276, rating: 4.3, status: "Available", librarySection: "Lifestyle" },93 { id: 1008, isbn: "978-0525509288", title: "The Biomimicry Revolution", author: "Dr. James Whitfield", genre: "Biology", yearPublished: 2020, pages: 345, rating: 4.5, status: "Available", librarySection: "Science" },94 { id: 1009, isbn: "978-0345391803", title: "Symphonies in Code", author: "Aria Blackwood", genre: "Programming", yearPublished: 2022, pages: 423, rating: 4.7, status: "Checked Out", librarySection: "Computer Science", borrowedBy: "Emma Davis" },95 { id: 1010, isbn: "978-0812988407", title: "Urban Gardens & Green Spaces", author: "Miguel Santos", genre: "Gardening", yearPublished: 2021, pages: 189, rating: 4.1, status: "Available", librarySection: "Lifestyle" },96 { id: 1011, isbn: "978-0374533557", title: "The Psychology of Innovation", author: "Dr. Rachel Kim", genre: "Psychology", yearPublished: 2019, pages: 312, rating: 4.6, status: "Reserved", librarySection: "Psychology" },97 { id: 1012, isbn: "978-0593229439", title: "Climate Solutions for Tomorrow", author: "Dr. Hassan Al-Rashid", genre: "Environmental Science", yearPublished: 2022, pages: 398, rating: 4.8, status: "Available", librarySection: "Science" },98];99100export const rowSelectionHeaders: ColumnDef[] = [101 { accessor: "id", label: "Book ID", width: 80, sortable: true, type: "number" },102 { accessor: "isbn", label: "ISBN", width: 120, sortable: true, type: "string" },103 { accessor: "title", label: "Title", minWidth: 150, width: "1fr", sortable: true, type: "string" },104 { accessor: "author", label: "Author", width: 140, sortable: true, type: "string" },105 { accessor: "genre", label: "Genre", width: 120, sortable: true, type: "string" },106 { accessor: "yearPublished", label: "Year", width: 80, sortable: true, type: "number" },107 { accessor: "pages", label: "Pages", width: 80, sortable: true, type: "number" },108 { accessor: "rating", label: "Rating", width: 80, sortable: true, type: "number" },109 { accessor: "status", label: "Status", width: 100, sortable: true, type: "string" },110 { accessor: "librarySection", label: "Section", width: 120, sortable: true, type: "string" },111];112113export const rowSelectionConfig = {114 headers: rowSelectionHeaders,115 rows: rowSelectionData,116 tableProps: {117 enableRowSelection: true,118 columnResizing: true,119 columnReordering: true,120 selectableCells: true,121 },122} as const;123
Single selection example
Selected: None
React TSX
Copy
1
Click to select example
Selected: None
React TSX
Copy
1
Programmatic selection example
Ready · Selected: None
React TSX
Copy
1
Props
Row Selection Configuration
| Property | Required | Description | Example |
|---|---|---|---|
Property | Required | Description | Example |
enableRowSelectionboolean | Optional | Enables row selection via checkboxes, click, keyboard, or TableAPI. | |
rowSelectionModeenum | Optional | Multiple (default) allows many selected rows; single replaces the previous selection and hides select-all. Options: single multiple | |
selectRowOnClickboolean | Optional | Selecting a data cell selects the row. Prefer selectableCells={false} for a pure click-to-select UX. | |
showRowSelectionColumnboolean | Optional | When false, hides the checkbox column. Selection still works via click, keyboard, or API. Default true. | |
getRowId(props: { row: Row }) => string | null | undefined | Optional | Stable row id so selection survives sort, filter, and pagination. | |
onRowSelectionChange(props: RowSelectionChangeProps) => void | Optional | Fires when selection changes. |
RowSelectionChangeProps
| Property | Required | Description | Example |
|---|---|---|---|
Property | Required | Description | Example |
row | Required | The complete row object that was selected or deselected | |
isSelectedboolean | Required | Boolean indicating whether the row was selected (true) or deselected (false) | |
selectedRowsSet<string> | Required | Set containing the IDs of all currently selected rows |