MCPcopy Index your code
hub / github.com/TanStack/table / selectRowsFn

Function selectRowsFn

packages/table-core/src/features/RowSelection.ts:581–620  ·  view source on GitHub ↗
(
  table: Table<TData>,
  rowModel: RowModel<TData>
)

Source from the content-addressed store, hash-verified

579}
580
581export function selectRowsFn<TData extends RowData>(
582 table: Table<TData>,
583 rowModel: RowModel<TData>
584): RowModel<TData> {
585 const rowSelection = table.getState().rowSelection
586
587 const newSelectedFlatRows: Row<TData>[] = []
588 const newSelectedRowsById: Record<string, Row<TData>> = {}
589
590 // Filters top level and nested rows
591 const recurseRows = (rows: Row<TData>[], depth = 0): Row<TData>[] => {
592 return rows
593 .map(row => {
594 const isSelected = isRowSelected(row, rowSelection)
595
596 if (isSelected) {
597 newSelectedFlatRows.push(row)
598 newSelectedRowsById[row.id] = row
599 }
600
601 if (row.subRows?.length) {
602 row = {
603 ...row,
604 subRows: recurseRows(row.subRows, depth + 1),
605 }
606 }
607
608 if (isSelected) {
609 return row
610 }
611 })
612 .filter(Boolean) as Row<TData>[]
613 }
614
615 return {
616 rows: recurseRows(rowModel.rows),
617 flatRows: newSelectedFlatRows,
618 rowsById: newSelectedRowsById,
619 }
620}
621
622export function isRowSelected<TData extends RowData>(
623 row: Row<TData>,

Callers 1

RowSelection.tsFile · 0.85

Calls 1

recurseRowsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…