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

Function selectRowsFn

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

Source from the content-addressed store, hash-verified

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

Callers 1

RowSelection.tsFile · 0.85

Calls 1

recurseRowsFunction · 0.85

Tested by

no test coverage detected