package.src.utils.getExpandedRowModel.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of table-core Show documentation
Show all versions of table-core Show documentation
Headless UI for building powerful tables & datagrids for TS/JS.
The newest version!
import { Table, Row, RowModel, RowData } from '../types'
import { memo } from '../utils'
export function getExpandedRowModel(): (
table: Table
) => () => RowModel {
return table =>
memo(
() => [
table.getState().expanded,
table.getPreExpandedRowModel(),
table.options.paginateExpandedRows,
],
(expanded, rowModel, paginateExpandedRows) => {
if (
!rowModel.rows.length ||
(expanded !== true && !Object.keys(expanded ?? {}).length)
) {
return rowModel
}
if (!paginateExpandedRows) {
// Only expand rows at this point if they are being paginated
return rowModel
}
return expandRows(rowModel)
},
{
key: process.env.NODE_ENV === 'development' && 'getExpandedRowModel',
debug: () => table.options.debugAll ?? table.options.debugTable,
}
)
}
export function expandRows(rowModel: RowModel) {
const expandedRows: Row[] = []
const handleRow = (row: Row) => {
expandedRows.push(row)
if (row.subRows?.length && row.getIsExpanded()) {
row.subRows.forEach(handleRow)
}
}
rowModel.rows.forEach(handleRow)
return {
rows: expandedRows,
flatRows: rowModel.flatRows,
rowsById: rowModel.rowsById,
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy