diff --git a/docs/api/features/pagination.md b/docs/api/features/pagination.md index 40e9861e9a..0befc42a21 100644 --- a/docs/api/features/pagination.md +++ b/docs/api/features/pagination.md @@ -190,10 +190,10 @@ getPageCount: () => number Returns the page count. If manually paginating or controlling the pagination state, this will come directly from the `options.pageCount` table option, otherwise it will be calculated from the table data using the total row count and current page size. -### `getPrePaginationRowModel` +### `getPrePaginatedRowModel` ```tsx -getPrePaginationRowModel: () => RowModel +getPrePaginatedRowModel: () => RowModel ``` Returns the row model for the table before any pagination has been applied. diff --git a/docs/guide/pagination.md b/docs/guide/pagination.md index 636ffb9459..bcc8b076a8 100644 --- a/docs/guide/pagination.md +++ b/docs/guide/pagination.md @@ -63,7 +63,7 @@ const table = useTable({ If you decide that you need to use server-side pagination, here is how you can implement it. -No pagination row model is needed for server-side pagination, but if you have provided it for other tables that do need it in a shared component, you can still turn off the client-side pagination by setting the `manualPagination` option to `true`. Setting the `manualPagination` option to `true` will tell the table instance to use the `table.getPrePaginationRowModel` row model under the hood, and it will make the table instance assume that the `data` that you pass in is already paginated. +No pagination row model is needed for server-side pagination, but if you have provided it for other tables that do need it in a shared component, you can still turn off the client-side pagination by setting the `manualPagination` option to `true`. Setting the `manualPagination` option to `true` will tell the table instance to use the `table.getPrePaginatedRowModel` row model under the hood, and it will make the table instance assume that the `data` that you pass in is already paginated. #### Page Count and Row Count diff --git a/docs/guide/row-models.md b/docs/guide/row-models.md index a095062abd..e8cdf7ed25 100644 --- a/docs/guide/row-models.md +++ b/docs/guide/row-models.md @@ -88,7 +88,7 @@ For normal rendering use cases, you will probably only need to use the `table.ge - `getPreExpandedRowModel` - returns a row model that only includes root level rows with no expanded sub-rows included. Still includes sorting. - `getPaginatedRowModel` - returns a row model that only includes the rows that should be displayed on the current page based on the pagination state. -- `getPrePaginationRowModel` - returns a row model without pagination applied (includes all rows). +- `getPrePaginatedRowModel` - returns a row model without pagination applied (includes all rows). - `getSelectedRowModel` - returns a row model of all selected rows (but only based on the data that was passed to the table). Runs after getCoreRowModel. - `getPreSelectedRowModel` - returns a row model before row selection is applied (Just returns getCoreRowModel). diff --git a/examples/angular/filters/src/app/app.component.html b/examples/angular/filters/src/app/app.component.html index e121dbab64..d82c781fd2 100644 --- a/examples/angular/filters/src/app/app.component.html +++ b/examples/angular/filters/src/app/app.component.html @@ -122,7 +122,7 @@ } -
{{ table.getPrePaginationRowModel().rows.length }} Rows
+
{{ table.getPrePaginatedRowModel().rows.length }} Rows
) diff --git a/examples/react/custom-features/src/main.tsx b/examples/react/custom-features/src/main.tsx index ba03804090..f13defbf78 100644 --- a/examples/react/custom-features/src/main.tsx +++ b/examples/react/custom-features/src/main.tsx @@ -171,9 +171,9 @@ function App() { const table = useTable({ _features: { DensityFeature }, // pass our custom feature to the table to be instantiated upon creation _rowModels: { - Filtered: createFilteredRowModel(), - Paginated: createPaginatedRowModel(), - Sorted: createSortedRowModel(), + filteredRowModel: createFilteredRowModel(), + paginatedRowModel: createPaginatedRowModel(), + sortedRowModel: createSortedRowModel(), }, columns, data, diff --git a/examples/react/editable-data/src/main.tsx b/examples/react/editable-data/src/main.tsx index 2a05902228..0a3c6c6847 100644 --- a/examples/react/editable-data/src/main.tsx +++ b/examples/react/editable-data/src/main.tsx @@ -26,8 +26,8 @@ const _features = tableFeatures({ RowPagination, ColumnFiltering }) const options = tableOptions({ _features, _rowModels: { - Filtered: createFilteredRowModel(), - Paginated: createPaginatedRowModel(), + filteredRowModel: createFilteredRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, }) diff --git a/examples/react/expanding/src/main.tsx b/examples/react/expanding/src/main.tsx index 1e8b05df66..d838d779f6 100644 --- a/examples/react/expanding/src/main.tsx +++ b/examples/react/expanding/src/main.tsx @@ -130,9 +130,9 @@ function App() { const table = useTable({ _features, _rowModels: { - Filtered: createFilteredRowModel(), - Paginated: createPaginatedRowModel(), - Sorted: createSortedRowModel(), + filteredRowModel: createFilteredRowModel(), + paginatedRowModel: createPaginatedRowModel(), + sortedRowModel: createSortedRowModel(), }, columns, data, diff --git a/examples/react/filters-faceted/src/main.tsx b/examples/react/filters-faceted/src/main.tsx index a93ebbbfc6..9e41c4064d 100644 --- a/examples/react/filters-faceted/src/main.tsx +++ b/examples/react/filters-faceted/src/main.tsx @@ -107,12 +107,12 @@ function App() { sortingFns, }, _rowModels: { - Filtered: createFilteredRowModel(), // client-side filtering - Paginated: createPaginatedRowModel(), - Sorted: createSortedRowModel(), - Faceted: createFacetedRowModel(), // client-side faceting - FacetedMinMax: createFacetedMinMaxValues(), // generate min/max values for range filter - FacetedUnique: createFacetedUniqueValues(), // generate unique values for select filter/autocomplete + filteredRowModel: createFilteredRowModel(), // client-side filtering + paginatedRowModel: createPaginatedRowModel(), + sortedRowModel: createSortedRowModel(), + facetedRowModel: createFacetedRowModel(), // client-side faceting + facetedMinMaxValues: createFacetedMinMaxValues(), // generate min/max values for range filter + facetedUniqueValues: createFacetedUniqueValues(), // generate unique values for select filter/autocomplete }, columns, data, @@ -247,7 +247,7 @@ function App() { ))} -
{table.getPrePaginationRowModel().rows.length} Rows
+
{table.getPrePaginatedRowModel().rows.length} Rows
diff --git a/examples/react/filters-fuzzy/src/main.tsx b/examples/react/filters-fuzzy/src/main.tsx index b6df4fb2cc..1324aca011 100644 --- a/examples/react/filters-fuzzy/src/main.tsx +++ b/examples/react/filters-fuzzy/src/main.tsx @@ -133,9 +133,9 @@ function App() { filterFns, }, _rowModels: { - Filtered: createFilteredRowModel(), - Paginated: createPaginatedRowModel(), - Sorted: createSortedRowModel(), + filteredRowModel: createFilteredRowModel(), + paginatedRowModel: createPaginatedRowModel(), + sortedRowModel: createSortedRowModel(), }, columns, data, @@ -294,7 +294,7 @@ function App() { ))} -
{table.getPrePaginationRowModel().rows.length} Rows
+
{table.getPrePaginatedRowModel().rows.length} Rows
diff --git a/examples/react/filters/src/main.tsx b/examples/react/filters/src/main.tsx index 9177b14c6d..bceddcfe43 100644 --- a/examples/react/filters/src/main.tsx +++ b/examples/react/filters/src/main.tsx @@ -105,9 +105,9 @@ function App() { sortingFns, }, _rowModels: { - Filtered: createFilteredRowModel(), // client side filtering - Sorted: createSortedRowModel(), - Paginated: createPaginatedRowModel(), + filteredRowModel: createFilteredRowModel(), // client side filtering + sortedRowModel: createSortedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, columns, data, @@ -244,7 +244,7 @@ function App() { ))} -
{table.getPrePaginationRowModel().rows.length} Rows
+
{table.getPrePaginatedRowModel().rows.length} Rows
diff --git a/examples/react/full-width-table/src/main.tsx b/examples/react/full-width-table/src/main.tsx index a5f2ced3a1..39bebed3e0 100644 --- a/examples/react/full-width-table/src/main.tsx +++ b/examples/react/full-width-table/src/main.tsx @@ -73,7 +73,7 @@ function App() { const table = useTable({ _rowModels: { - Paginated: createPaginatedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, columns, data, diff --git a/examples/react/fully-controlled/src/main.tsx b/examples/react/fully-controlled/src/main.tsx index d52ef91969..d71ed639e0 100644 --- a/examples/react/fully-controlled/src/main.tsx +++ b/examples/react/fully-controlled/src/main.tsx @@ -81,7 +81,7 @@ function App() { // Create the table and pass your options const table = useTable({ _rowModels: { - Paginated: createPaginatedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, columns, data, diff --git a/examples/react/grouping/src/main.tsx b/examples/react/grouping/src/main.tsx index 5ed864426e..fe9421efce 100644 --- a/examples/react/grouping/src/main.tsx +++ b/examples/react/grouping/src/main.tsx @@ -22,17 +22,17 @@ import type { Person } from './makeData' const tableHelper = createTableHelper({ _features: { ColumnFiltering, - RowPagination, - RowSorting, ColumnGrouping, RowExpanding, + RowPagination, + RowSorting, }, _rowModels: { - Filtered: createFilteredRowModel(), - Paginated: createPaginatedRowModel(), - Sorted: createSortedRowModel(), - Grouped: createGroupedRowModel(), - Expanded: createExpandedRowModel(), + filteredRowModel: createFilteredRowModel(), + paginatedRowModel: createPaginatedRowModel(), + sortedRowModel: createSortedRowModel(), + groupedRowModel: createGroupedRowModel(), + expandedRowModel: createExpandedRowModel(), }, TData: {} as Person, }) diff --git a/examples/react/kitchen-sink/src/App.tsx b/examples/react/kitchen-sink/src/App.tsx index fb809fd515..3bcc64ba2f 100644 --- a/examples/react/kitchen-sink/src/App.tsx +++ b/examples/react/kitchen-sink/src/App.tsx @@ -86,13 +86,13 @@ export const App = () => { const table = useTable({ _rowModels: { - Filtered: createFilteredRowModel(), - Paginated: createPaginatedRowModel(), - Sorted: createSortedRowModel(), - Grouped: createGroupedRowModel(), - Faceted: createFacetedRowModel(), - FacetedMinMax: createFacetedMinMaxValues(), - FacetedUnique: createFacetedUniqueValues(), + filteredRowModel: createFilteredRowModel(), + paginatedRowModel: createPaginatedRowModel(), + sortedRowModel: createSortedRowModel(), + groupedRowModel: createGroupedRowModel(), + facetedRowModel: createFacetedRowModel(), + facetedMinMaxValues: createFacetedMinMaxValues(), + facetedUniqueValues: createFacetedUniqueValues(), }, columns, data, @@ -214,7 +214,7 @@ export const App = () => { rowSelection={rowSelection} setPageIndex={table.setPageIndex} setPageSize={table.setPageSize} - totalRows={table.getPrePaginationRowModel().rows.length} + totalRows={table.getPrePaginatedRowModel().rows.length} />
{JSON.stringify(table.getState(), null, 2)}
diff --git a/examples/react/material-ui-pagination/src/main.tsx b/examples/react/material-ui-pagination/src/main.tsx index 0cbd5bcce7..a3b14d87ff 100644 --- a/examples/react/material-ui-pagination/src/main.tsx +++ b/examples/react/material-ui-pagination/src/main.tsx @@ -110,8 +110,8 @@ function LocalTable({ }) { const table = useTable({ _rowModels: { - Filtered: createFilteredRowModel(), - Paginated: createPaginatedRowModel(), + filteredRowModel: createFilteredRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, columns, data, diff --git a/examples/react/pagination/src/main.tsx b/examples/react/pagination/src/main.tsx index 42f3075042..80d3de1c92 100644 --- a/examples/react/pagination/src/main.tsx +++ b/examples/react/pagination/src/main.tsx @@ -114,9 +114,9 @@ function MyTable({ _features, _processingFns, _rowModels: { - Sorted: createSortedRowModel(), - Filtered: createFilteredRowModel(), - Paginated: createPaginatedRowModel(), + sortedRowModel: createSortedRowModel(), + filteredRowModel: createFilteredRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, columns, data, diff --git a/examples/react/row-pinning/src/main.tsx b/examples/react/row-pinning/src/main.tsx index 212d699376..f0978e3dcc 100644 --- a/examples/react/row-pinning/src/main.tsx +++ b/examples/react/row-pinning/src/main.tsx @@ -156,9 +156,9 @@ function App() { const table = useTable({ _features, _rowModels: { - Filtered: createFilteredRowModel(), - Expanded: createExpandedRowModel(), - Paginated: createPaginatedRowModel(), + filteredRowModel: createFilteredRowModel(), + expandedRowModel: createExpandedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, columns, data, diff --git a/examples/react/row-selection/src/main.tsx b/examples/react/row-selection/src/main.tsx index c06bd19edd..23c3c2a36a 100644 --- a/examples/react/row-selection/src/main.tsx +++ b/examples/react/row-selection/src/main.tsx @@ -112,8 +112,8 @@ function App() { const table = useTable({ _features, _rowModels: { - Filtered: createFilteredRowModel(), - Paginated: createPaginatedRowModel(), + filteredRowModel: createFilteredRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, columns, data, diff --git a/examples/react/sorting/src/main.tsx b/examples/react/sorting/src/main.tsx index f7ff64dbff..7018a249fe 100644 --- a/examples/react/sorting/src/main.tsx +++ b/examples/react/sorting/src/main.tsx @@ -93,7 +93,7 @@ function App() { sortingFns, }, _rowModels: { - Sorted: createSortedRowModel(), // client-side sorting + sortedRowModel: createSortedRowModel(), // client-side sorting }, columns, data, @@ -197,7 +197,7 @@ const rootElement = document.getElementById('root') if (!rootElement) throw new Error('Failed to find the root element') ReactDOM.createRoot(rootElement).render( - + // - , + // , ) diff --git a/examples/react/sub-components/src/main.tsx b/examples/react/sub-components/src/main.tsx index 91ea303420..2da9bb74f9 100644 --- a/examples/react/sub-components/src/main.tsx +++ b/examples/react/sub-components/src/main.tsx @@ -112,7 +112,7 @@ function Table({ const table = useTable({ _features: { RowExpanding }, _rowModels: { - Expanded: createExpandedRowModel(), + expandedRowModel: createExpandedRowModel(), }, columns, data, diff --git a/examples/react/virtualized-columns/src/main.tsx b/examples/react/virtualized-columns/src/main.tsx index bf48f24793..c945e15937 100644 --- a/examples/react/virtualized-columns/src/main.tsx +++ b/examples/react/virtualized-columns/src/main.tsx @@ -23,7 +23,7 @@ function App() { const table = useTable({ _features: { ColumnSizing, RowSorting }, - _rowModels: { Sorted: createSortedRowModel() }, + _rowModels: { sortedRowModel: createSortedRowModel() }, columns, data, debugTable: true, diff --git a/examples/react/virtualized-infinite-scrolling/src/main.tsx b/examples/react/virtualized-infinite-scrolling/src/main.tsx index 9d8a1db1fa..b0d589cc66 100644 --- a/examples/react/virtualized-infinite-scrolling/src/main.tsx +++ b/examples/react/virtualized-infinite-scrolling/src/main.tsx @@ -126,7 +126,7 @@ function App() { const table = useTable({ _features: { ColumnSizing, RowSorting }, - _rowModels: { Sorted: createSortedRowModel() }, + _rowModels: { sortedRowModel: createSortedRowModel() }, data: flatData, columns, state: { diff --git a/examples/react/virtualized-rows/src/main.tsx b/examples/react/virtualized-rows/src/main.tsx index 9cf16ceb3e..432891b8c0 100644 --- a/examples/react/virtualized-rows/src/main.tsx +++ b/examples/react/virtualized-rows/src/main.tsx @@ -66,7 +66,7 @@ function App() { const table = useTable({ _features: { ColumnSizing, RowSorting }, - _rowModels: { Sorted: createSortedRowModel() }, + _rowModels: { sortedRowModel: createSortedRowModel() }, columns, data, debugTable: true, diff --git a/examples/solid/filters/src/App.tsx b/examples/solid/filters/src/App.tsx index e9d8a427e4..f539d3b411 100644 --- a/examples/solid/filters/src/App.tsx +++ b/examples/solid/filters/src/App.tsx @@ -88,10 +88,10 @@ function App() { const table = createTable({ _features, _rowModels: { - Faceted: createFacetedRowModel(), - FacetedMinMax: createFacetedMinMaxValues(), - FacetedUnique: createFacetedUniqueValues(), - Filtered: createFilteredRowModel(), + facetedRowModel: createFacetedRowModel(), + facetedMinMaxValues: createFacetedMinMaxValues(), + facetedUniqueValues: createFacetedUniqueValues(), + filteredRowModel: createFilteredRowModel(), }, get data() { return data() diff --git a/examples/solid/sorting/src/App.tsx b/examples/solid/sorting/src/App.tsx index bdb29d8939..e2c9a9f617 100644 --- a/examples/solid/sorting/src/App.tsx +++ b/examples/solid/sorting/src/App.tsx @@ -72,7 +72,7 @@ function App() { const table = createTable({ _features, _rowModels: { - Sorted: createSortedRowModel(), + sortedRowModel: createSortedRowModel(), }, get data() { return data() diff --git a/examples/svelte/column-pinning/src/App.svelte b/examples/svelte/column-pinning/src/App.svelte index 417b6d8923..df3fe828e0 100644 --- a/examples/svelte/column-pinning/src/App.svelte +++ b/examples/svelte/column-pinning/src/App.svelte @@ -91,7 +91,7 @@ const options: TableOptions = { _features, - _rowModels: { Sorted: createSortedRowModel() }, + _rowModels: { sortedRowModel: createSortedRowModel() }, get data() { return data }, diff --git a/examples/svelte/filtering/src/App.svelte b/examples/svelte/filtering/src/App.svelte index b6ac9035a9..42f5a5e959 100644 --- a/examples/svelte/filtering/src/App.svelte +++ b/examples/svelte/filtering/src/App.svelte @@ -63,8 +63,8 @@ const options: TableOptions = { _features, _rowModels: { - Filtered: createFilteredRowModel(), - Paginated: createPaginatedRowModel(), + filteredRowModel: createFilteredRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, data: makeData(25), columns, diff --git a/examples/svelte/sorting/src/App.svelte b/examples/svelte/sorting/src/App.svelte index daf80ccecf..c8028a8599 100644 --- a/examples/svelte/sorting/src/App.svelte +++ b/examples/svelte/sorting/src/App.svelte @@ -91,7 +91,7 @@ const options: TableOptions = { _features, _rowModels: { - Sorted: createSortedRowModel(), + sortedRowModel: createSortedRowModel(), }, get data() { return data diff --git a/packages/react-table/src/tableHelper.ts b/packages/react-table/src/tableHelper.ts index 0f70c6543e..3c965897ce 100644 --- a/packages/react-table/src/tableHelper.ts +++ b/packages/react-table/src/tableHelper.ts @@ -1,6 +1,5 @@ import { constructTableHelper } from '@tanstack/table-core' import { useTable } from './useTable' -import type { ProcessingFns } from '../../table-core/dist/esm/types/ProcessingFns' import type { RowData, Table, diff --git a/packages/react-table/src/useTable.ts b/packages/react-table/src/useTable.ts index c83547c1ca..fd72305f2f 100644 --- a/packages/react-table/src/useTable.ts +++ b/packages/react-table/src/useTable.ts @@ -4,7 +4,6 @@ import { coreFeatures, getInitialTableState, } from '@tanstack/table-core' -import type { ProcessingFns } from '../../table-core/dist/esm/types/ProcessingFns' import type { RowData, Table, diff --git a/packages/table-core/src/core/coreFeatures.ts b/packages/table-core/src/core/coreFeatures.ts index d160ff2bfd..fb6c34135a 100644 --- a/packages/table-core/src/core/coreFeatures.ts +++ b/packages/table-core/src/core/coreFeatures.ts @@ -1,7 +1,8 @@ import { Cells } from './cells/Cells' import { Columns } from './columns/Columns' import { Headers } from './headers/Headers' +import { RowModels } from './row-models/RowModels' import { Rows } from './rows/Rows' import { Tables } from './table/Tables' -export const coreFeatures = { Cells, Columns, Headers, Rows, Tables } +export const coreFeatures = { Cells, Columns, Headers, Rows, RowModels, Tables } diff --git a/packages/table-core/src/core/row-models/RowModels.ts b/packages/table-core/src/core/row-models/RowModels.ts new file mode 100644 index 0000000000..cf785b6da6 --- /dev/null +++ b/packages/table-core/src/core/row-models/RowModels.ts @@ -0,0 +1,63 @@ +import { assignAPIs } from '../../utils' +import { + table_getCoreRowModel, + table_getExpandedRowModel, + table_getFilteredRowModel, + table_getGroupedRowModel, + table_getPaginatedRowModel, + table_getPreExpandedRowModel, + table_getPreFilteredRowModel, + table_getPreGroupedRowModel, + table_getPrePaginatedRowModel, + table_getPreSortedRowModel, + table_getRowModel, + table_getSortedRowModel, +} from './RowModels.utils' +import type { Table } from '../../types/Table' +import type { RowData } from '../../types/type-utils' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' + +export const RowModels: TableFeature = { + constructTable: ( + table: Table, + ): void => { + assignAPIs(table, table, [ + { + fn: () => table_getCoreRowModel(table), + }, + { + fn: () => table_getRowModel(table), + }, + { + fn: () => table_getPreFilteredRowModel(table), + }, + { + fn: () => table_getFilteredRowModel(table), + }, + { + fn: () => table_getPreGroupedRowModel(table), + }, + { + fn: () => table_getGroupedRowModel(table), + }, + { + fn: () => table_getPreExpandedRowModel(table), + }, + { + fn: () => table_getExpandedRowModel(table), + }, + { + fn: () => table_getPrePaginatedRowModel(table), + }, + { + fn: () => table_getPaginatedRowModel(table), + }, + { + fn: () => table_getPreSortedRowModel(table), + }, + { + fn: () => table_getSortedRowModel(table), + }, + ]) + }, +} diff --git a/packages/table-core/src/core/row-models/RowModels.types.ts b/packages/table-core/src/core/row-models/RowModels.types.ts new file mode 100644 index 0000000000..ecd0c6a81f --- /dev/null +++ b/packages/table-core/src/core/row-models/RowModels.types.ts @@ -0,0 +1,69 @@ +import type { Table_RowModels_Faceted } from '../../features/column-faceting/ColumnFaceting.types' +import type { Table_RowModels_Filtered } from '../../features/column-filtering/ColumnFiltering.types' +import type { Table_RowModels_Grouped } from '../../features/column-grouping/ColumnGrouping.types' +import type { Table_RowModels_Expanded } from '../../features/row-expanding/RowExpanding.types' +import type { Table_RowModels_Paginated } from '../../features/row-pagination/RowPagination.types' +import type { Table_RowModels_Sorted } from '../../features/row-sorting/RowSorting.types' +import type { Row } from '../../types/Row' +import type { Table } from '../../types/Table' +import type { TableFeatures } from '../../types/TableFeatures' +import type { RowData } from '../../types/type-utils' + +export interface RowModel< + TFeatures extends TableFeatures, + TData extends RowData, +> { + rows: Array> + flatRows: Array> + rowsById: Record> +} + +export interface CreateRowModel_Core< + TFeatures extends TableFeatures, + TData extends RowData, +> { + /** + * This required option is a factory for a function that computes and returns the core row model for the table. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getcorerowmodel) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables) + */ + coreRowModel?: ( + table: Table, + ) => () => RowModel +} + +export interface CachedRowModel_Core< + TFeatures extends TableFeatures, + TData extends RowData, +> { + coreRowModel?: () => RowModel +} + +export interface Table_RowModels_Core< + TFeatures extends TableFeatures, + TData extends RowData, +> { + /** + * Returns the core row model before any processing has been applied. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getcorerowmodel) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables) + */ + getCoreRowModel: () => RowModel + /** + * Returns the final model after all processing from other used features has been applied. This is the row model that is most commonly used for rendering. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getrowmodel) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables) + */ + getRowModel: () => RowModel +} + +export type Table_RowModels< + TFeatures extends TableFeatures, + TData extends RowData, +> = Table_RowModels_Core & + Table_RowModels_Faceted & + Table_RowModels_Filtered & + Table_RowModels_Grouped & + Table_RowModels_Expanded & + Table_RowModels_Paginated & + Table_RowModels_Sorted diff --git a/packages/table-core/src/core/row-models/RowModels.utils.ts b/packages/table-core/src/core/row-models/RowModels.utils.ts new file mode 100644 index 0000000000..5aab81a3da --- /dev/null +++ b/packages/table-core/src/core/row-models/RowModels.utils.ts @@ -0,0 +1,140 @@ +import { createCoreRowModel } from './createCoreRowModel' +import type { Table_Internal } from '../../types/Table' +import type { TableFeatures } from '../../types/TableFeatures' +import type { RowData } from '../../types/type-utils' +import type { RowModel } from './RowModels.types' + +export function table_getCoreRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + if (!table._rowModels.coreRowModel) { + table._rowModels.coreRowModel = + table.options._rowModels?.coreRowModel?.(table) ?? + createCoreRowModel()(table) + } + + return table._rowModels.coreRowModel() +} + +export function table_getRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + return table.getPaginatedRowModel() +} + +export function table_getPreFilteredRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal) { + return table.getCoreRowModel() +} + +export function table_getFilteredRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + if (!table._rowModels.filteredRowModel) { + table._rowModels.filteredRowModel = + table.options._rowModels?.filteredRowModel?.(table) + } + + if (table.options.manualFiltering || !table._rowModels.filteredRowModel) { + return table.getPreFilteredRowModel() + } + + return table._rowModels.filteredRowModel() +} + +export function table_getPreGroupedRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + return table.getFilteredRowModel() +} + +export function table_getGroupedRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + if (!table._rowModels.groupedRowModel) { + table._rowModels.groupedRowModel = + table.options._rowModels?.groupedRowModel?.(table) + } + + if (table.options.manualGrouping || !table._rowModels.groupedRowModel) { + return table.getPreGroupedRowModel() + } + + return table._rowModels.groupedRowModel() +} + +export function table_getPreExpandedRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + return table.getSortedRowModel() +} + +export function table_getExpandedRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + if (!table._rowModels.expandedRowModel) { + table._rowModels.expandedRowModel = + table.options._rowModels?.expandedRowModel?.(table) + } + + if (table.options.manualExpanding || !table._rowModels.expandedRowModel) { + return table.getPreExpandedRowModel() + } + + return table._rowModels.expandedRowModel() +} + +export function table_getPrePaginatedRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + return table.getExpandedRowModel() +} + +export function table_getPaginatedRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + if (!table._rowModels.paginatedRowModel) { + table._rowModels.paginatedRowModel = + table.options._rowModels?.paginatedRowModel?.(table) + } + + if (table.options.manualPagination || !table._rowModels.paginatedRowModel) { + return table.getPrePaginatedRowModel() + } + + return table._rowModels.paginatedRowModel() +} + +export function table_getPreSortedRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + return table.getGroupedRowModel() +} + +export function table_getSortedRowModel< + TFeatures extends TableFeatures, + TData extends RowData, +>(table: Table_Internal): RowModel { + if (!table._rowModels.sortedRowModel) { + table._rowModels.sortedRowModel = + table.options._rowModels?.sortedRowModel?.(table) + } + + if (table.options.manualSorting || !table._rowModels.sortedRowModel) { + return table.getPreSortedRowModel() + } + + return table._rowModels.sortedRowModel() +} diff --git a/packages/table-core/src/core/table/createCoreRowModel.ts b/packages/table-core/src/core/row-models/createCoreRowModel.ts similarity index 93% rename from packages/table-core/src/core/table/createCoreRowModel.ts rename to packages/table-core/src/core/row-models/createCoreRowModel.ts index e2b7028418..1906a7894a 100644 --- a/packages/table-core/src/core/table/createCoreRowModel.ts +++ b/packages/table-core/src/core/row-models/createCoreRowModel.ts @@ -2,9 +2,9 @@ import { constructRow } from '../rows/constructRow' import { isDev, tableMemo } from '../../utils' import { table_getRowId } from '../rows/Rows.utils' import { table_autoResetPageIndex } from '../../features/row-pagination/RowPagination.utils' +import type { RowModel } from './RowModels.types' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' @@ -15,7 +15,7 @@ export function createCoreRowModel< return (table: Table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), - fnName: 'table.createCoreRowModel', + fnName: 'table.getCoreRowModel', memoDeps: () => [table.options.data], fn: (data) => _createCoreRowModel(table, data), onAfterUpdate: () => table_autoResetPageIndex(table), @@ -46,6 +46,7 @@ function _createCoreRowModel< ): Array> => { const rows = [] as Array> + console.time('constructing rows') for (let i = 0; i < originalRows.length; i++) { const originalRow = originalRows[i]! // Make the row @@ -76,6 +77,7 @@ function _createCoreRowModel< } } } + console.timeEnd('constructing rows') return rows } diff --git a/packages/table-core/src/core/rows/Rows.utils.ts b/packages/table-core/src/core/rows/Rows.utils.ts index 3b12698b11..65e5818967 100644 --- a/packages/table-core/src/core/rows/Rows.utils.ts +++ b/packages/table-core/src/core/rows/Rows.utils.ts @@ -4,8 +4,6 @@ import { table_getAllLeafColumns, table_getColumn, } from '../columns/Columns.utils' -import { table_getPrePaginationRowModel } from '../../features/row-pagination/RowPagination.utils' -import { table_getCoreRowModel, table_getRowModel } from '../table/Tables.utils' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -156,12 +154,11 @@ export function table_getRow< searchAll?: boolean, ): Row { // TODO - simplify this across different row models - let row = ( - searchAll ? table_getPrePaginationRowModel(table) : table_getRowModel(table) - ).rowsById[rowId] + let row = (searchAll ? table.getPrePaginatedRowModel() : table.getRowModel()) + .rowsById[rowId] if (!row) { - row = table_getCoreRowModel(table).rowsById[rowId] + row = table.getCoreRowModel().rowsById[rowId] if (!row) { if (process.env.NODE_ENV !== 'production') { throw new Error(`getRow could not find row with ID: ${rowId}`) diff --git a/packages/table-core/src/core/table/Tables.ts b/packages/table-core/src/core/table/Tables.ts index 2390a8374c..b34d184146 100644 --- a/packages/table-core/src/core/table/Tables.ts +++ b/packages/table-core/src/core/table/Tables.ts @@ -1,7 +1,5 @@ import { assignAPIs } from '../../utils' import { - table_getCoreRowModel, - table_getRowModel, table_getState, table_reset, table_setOptions, @@ -16,12 +14,6 @@ export const Tables: TableFeature = { table: Table, ): void => { assignAPIs(table, table, [ - { - fn: () => table_getCoreRowModel(table), - }, - { - fn: () => table_getRowModel(table), - }, { fn: () => table_getState(table), }, diff --git a/packages/table-core/src/core/table/Tables.types.ts b/packages/table-core/src/core/table/Tables.types.ts index 6b1eb4bac7..d058254a2c 100644 --- a/packages/table-core/src/core/table/Tables.types.ts +++ b/packages/table-core/src/core/table/Tables.types.ts @@ -4,11 +4,7 @@ import type { CoreTableFeatures, TableFeatures, } from '../../types/TableFeatures' -import type { - CachedRowModels, - RowModel, - RowModelOptions, -} from '../../types/RowModel' +import type { CachedRowModels, CreateRowModels } from '../../types/RowModel' import type { TableOptions } from '../../types/TableOptions' import type { TableState } from '../../types/TableState' @@ -38,7 +34,7 @@ export interface TableOptions_Table< * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#_rowmodels) * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables) */ - _rowModels?: RowModelOptions + _rowModels?: CreateRowModels /** * Set this option to override any of the `autoReset...` feature options. * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#autoresetall) @@ -142,18 +138,6 @@ export interface Table_Table< TFeatures extends TableFeatures, TData extends RowData, > extends Table_CoreProperties { - /** - * Returns the core row model before any processing has been applied. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getcorerowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables) - */ - getCoreRowModel: () => RowModel - /** - * Returns the final model after all processing from other used features has been applied. This is the row model that is most commonly used for rendering. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getrowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables) - */ - getRowModel: () => RowModel /** * Call this function to get the table's current state. It's recommended to use this function and its state, especially when managing the table state manually. It is the exact same state used internally by the table for every feature and function it provides. * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getstate) diff --git a/packages/table-core/src/core/table/Tables.utils.ts b/packages/table-core/src/core/table/Tables.utils.ts index b3499b0b44..c0bf2d7941 100644 --- a/packages/table-core/src/core/table/Tables.utils.ts +++ b/packages/table-core/src/core/table/Tables.utils.ts @@ -1,9 +1,6 @@ -import { table_getPaginatedRowModel } from '../../features/row-pagination/RowPagination.utils' import { functionalUpdate } from '../../utils' -import { createCoreRowModel } from './createCoreRowModel' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' import type { Table_Internal } from '../../types/Table' import type { TableOptions } from '../../types/TableOptions' import type { TableState } from '../../types/TableState' @@ -66,23 +63,3 @@ export function table_setState< ): void { table.options.onStateChange?.(updater) } - -export function table_getCoreRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.Core) { - table._rowModels.Core = - table.options._rowModels?.Core?.(table) ?? - createCoreRowModel()(table) - } - - return table._rowModels.Core() -} - -export function table_getRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - return table_getPaginatedRowModel(table) -} diff --git a/packages/table-core/src/core/table/constructTable.ts b/packages/table-core/src/core/table/constructTable.ts index f8c791c491..f368f171e1 100644 --- a/packages/table-core/src/core/table/constructTable.ts +++ b/packages/table-core/src/core/table/constructTable.ts @@ -1,4 +1,5 @@ import { isDev } from '../../utils' +import type { CachedRowModels } from '../../types/RowModel' import type { Table_CoreProperties } from './Tables.types' import type { RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' @@ -39,7 +40,7 @@ export function constructTable< const coreInstance: Table_CoreProperties = { _features, // features get stored here immediately _processingFns, // processing functions get stored here - _rowModels: {}, // row models get cached here later + _rowModels: {} as CachedRowModels, // row models get cached here later options: { ...defaultOptions, ...options, diff --git a/packages/table-core/src/features/column-faceting/ColumnFaceting.types.ts b/packages/table-core/src/features/column-faceting/ColumnFaceting.types.ts index bb92eac664..2217a47864 100644 --- a/packages/table-core/src/features/column-faceting/ColumnFaceting.types.ts +++ b/packages/table-core/src/features/column-faceting/ColumnFaceting.types.ts @@ -1,10 +1,16 @@ +import type { Table } from '../../types/Table' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' export interface Column_ColumnFaceting< TFeatures extends TableFeatures, TData extends RowData, +> {} + +export interface Table_RowModels_Faceted< + TFeatures extends TableFeatures, + TData extends RowData, > { /** * A function that **computes and returns** a min/max tuple derived from `column.getFacetedRowModel`. Useful for displaying faceted result values. @@ -28,3 +34,45 @@ export interface Column_ColumnFaceting< */ getFacetedUniqueValues: () => Map } + +export interface CreateRowModel_Faceted< + TFeatures extends TableFeatures, + TData extends RowData, +> { + /** + * This function is used to retrieve the faceted min/max values. If using server-side faceting, this function is not required. To use client-side faceting, pass the exported `getFacetedMinMaxValues()` from your adapter to your table or implement your own. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-faceting#getfacetedminmaxvalues) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting) + */ + facetedMinMaxValues?: ( + table: Table, + columnId: string, + ) => () => [number, number] | undefined + /** + * This function is used to retrieve the faceted row model. If using server-side faceting, this function is not required. To use client-side faceting, pass the exported `getFacetedRowModel()` from your adapter to your table or implement your own. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-faceting#getfacetedrowmodel) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting) + */ + facetedRowModel?: ( + table: Table, + columnId: string, + ) => () => RowModel + /** + * This function is used to retrieve the faceted unique values. If using server-side faceting, this function is not required. To use client-side faceting, pass the exported `getFacetedUniqueValues()` from your adapter to your table or implement your own. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-faceting#getfaceteduniquevalues) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting) + */ + facetedUniqueValues?: ( + table: Table, + columnId: string, + ) => () => Map +} + +export interface CachedRowModel_Faceted< + TFeatures extends TableFeatures, + TData extends RowData, +> { + facetedRowModel?: (columnId: string) => () => RowModel + facetedMinMaxValues?: (columnId: string) => [number, number] + facetedUniqueValues?: (columnId: string) => Map +} diff --git a/packages/table-core/src/features/column-faceting/ColumnFaceting.utils.ts b/packages/table-core/src/features/column-faceting/ColumnFaceting.utils.ts index 8107511983..59b0a781fe 100644 --- a/packages/table-core/src/features/column-faceting/ColumnFaceting.utils.ts +++ b/packages/table-core/src/features/column-faceting/ColumnFaceting.utils.ts @@ -1,7 +1,6 @@ -import { table_getPreFilteredRowModel } from '../column-filtering/ColumnFiltering.utils' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table_Internal } from '../../types/Table' import type { Column } from '../../types/Column' @@ -14,7 +13,7 @@ export function column_getFacetedMinMaxValues< table: Table_Internal, ): () => [number, number] | undefined { return ( - table.options._rowModels?.FacetedMinMax?.(table, column.id) ?? + table.options._rowModels?.facetedMinMaxValues?.(table, column.id) ?? (() => undefined) ) } @@ -28,8 +27,8 @@ export function column_getFacetedRowModel< table: Table_Internal, ): () => RowModel { return ( - table.options._rowModels?.Faceted?.(table, column?.id ?? '') ?? - (() => table_getPreFilteredRowModel(table)) + table.options._rowModels?.facetedRowModel?.(table, column?.id ?? '') ?? + (() => table.getPreFilteredRowModel()) ) } @@ -42,7 +41,7 @@ export function column_getFacetedUniqueValues< table: Table_Internal, ): () => Map { return ( - table.options._rowModels?.FacetedUnique?.(table, column.id) ?? + table.options._rowModels?.facetedUniqueValues?.(table, column.id) ?? (() => new Map()) ) } diff --git a/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts b/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts index b4bf7466f4..1b1bb43301 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts @@ -1,7 +1,7 @@ import { isDev, tableMemo } from '../../utils' import { row_getUniqueValues } from '../../core/rows/Rows.utils' import { column_getFacetedRowModel } from './ColumnFaceting.utils' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -16,7 +16,7 @@ export function createFacetedMinMaxValues< return (table, columnId) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), - fnName: 'table.createFacetedMinMaxValues', + fnName: 'table.getFacetedMinMaxValues', memoDeps: () => [ column_getFacetedRowModel(table.getColumn(columnId), table)(), ], diff --git a/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts b/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts index 4bb1935927..401bd50029 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts @@ -1,14 +1,10 @@ import { isDev, tableMemo } from '../../utils' import { filterRows } from '../column-filtering/filterRowsUtils' import { table_getState } from '../../core/table/Tables.utils' -import { - table_getFilteredRowModel, - table_getPreFilteredRowModel, -} from '../column-filtering/ColumnFiltering.utils' import type { ColumnFiltersState } from '../column-filtering/ColumnFiltering.types' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' @@ -24,10 +20,10 @@ export function createFacetedRowModel< debug: isDev && (table.options.debugAll ?? table.options.debugTable), fnName: 'createFacetedRowModel', memoDeps: () => [ - table_getPreFilteredRowModel(table), + table.getPreFilteredRowModel(), table_getState(table).columnFilters, table_getState(table).globalFilter, - table_getFilteredRowModel(table), + table.getFilteredRowModel(), ], fn: (preRowModel, columnFilters, globalFilter) => _createFacetedRowModel( diff --git a/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts b/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts index 7b97e4e2a6..440e318aa5 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts @@ -15,7 +15,7 @@ export function createFacetedUniqueValues< return (table, columnId) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), - fnName: 'table.createFacetedUniqueValues', + fnName: 'table.getFacetedUniqueValues', memoDeps: () => [ column_getFacetedRowModel(table.getColumn(columnId), table)(), ], diff --git a/packages/table-core/src/features/column-filtering/ColumnFiltering.ts b/packages/table-core/src/features/column-filtering/ColumnFiltering.ts index 30b1b42bc0..f154f97bda 100644 --- a/packages/table-core/src/features/column-filtering/ColumnFiltering.ts +++ b/packages/table-core/src/features/column-filtering/ColumnFiltering.ts @@ -8,8 +8,6 @@ import { column_getIsFiltered, column_setFilterValue, getDefaultColumnFiltersState, - table_getFilteredRowModel, - table_getPreFilteredRowModel, table_resetColumnFilters, table_setColumnFilters, } from './ColumnFiltering.utils' @@ -123,12 +121,6 @@ export const ColumnFiltering: TableFeature = { { fn: (defaultState) => table_resetColumnFilters(table, defaultState), }, - { - fn: () => table_getPreFilteredRowModel(table), - }, - { - fn: () => table_getFilteredRowModel(table), - }, ]) }, } diff --git a/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts b/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts index 27af381e35..22ef18caf8 100644 --- a/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts +++ b/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts @@ -1,3 +1,4 @@ +import type { Table } from '../../types/Table' import type { BuiltInFilterFn } from '../../fns/filterFns' import type { CellData, @@ -6,7 +7,7 @@ import type { Updater, } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Row } from '../../types/Row' import type { Column } from '../../types/Column' @@ -102,20 +103,6 @@ export interface ColumnDef_ColumnFiltering< filterFn?: FilterFnOption } -export interface ColumnDef_ColumnFiltering_Unavailable< - TFeatures extends TableFeatures, - TData extends RowData, -> { - /** - * @deprecated Import the `ColumnFiltering` feature to use the column filtering APIs. - */ - enableColumnFilter?: boolean - /** - * @deprecated Import the `ColumnFiltering` feature to use the column filtering APIs. - */ - filterFn?: FilterFnOption -} - export interface Column_ColumnFiltering< TFeatures extends TableFeatures, TData extends RowData, @@ -226,37 +213,37 @@ export interface TableOptions_ColumnFiltering< onColumnFiltersChange?: OnChangeFn } -export interface TableOptions_ColumnFiltering_Unavailable< +export interface Table_ColumnFiltering< TFeatures extends TableFeatures, TData extends RowData, > { /** - * @deprecated Import the `ColumnFiltering` feature to use the column filtering APIs. - */ - enableColumnFilters?: boolean - /** - * @deprecated Import the `ColumnFiltering` feature to use the column filtering APIs. - */ - enableFilters?: boolean - /** - * @deprecated Import the `ColumnFiltering` feature to use the column filtering APIs. + * Resets the **columnFilters** state to `initialState.columnFilters`, or `true` can be passed to force a default blank state reset to `[]`. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#resetcolumnfilters) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) */ - filterFromLeafRows?: boolean + resetColumnFilters: (defaultState?: boolean) => void /** - * @deprecated Import the `ColumnFiltering` feature to use the column filtering APIs. + * Resets the **globalFilter** state to `initialState.globalFilter`, or `true` can be passed to force a default blank state reset to `undefined`. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#resetglobalfilter) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) */ - manualFiltering?: boolean + resetGlobalFilter: (defaultState?: boolean) => void /** - * @deprecated Import the `ColumnFiltering` feature to use the column filtering APIs. + * Sets or updates the `state.columnFilters` state. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#setcolumnfilters) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) */ - maxLeafRowFilterDepth?: number + setColumnFilters: (updater: Updater) => void /** - * @deprecated Import the `ColumnFiltering` feature to use the column filtering APIs. + * Sets or updates the `state.globalFilter` state. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#setglobalfilter) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) */ - onColumnFiltersChange?: OnChangeFn + setGlobalFilter: (updater: Updater) => void } -export interface Table_ColumnFiltering< +export interface Table_RowModels_Filtered< TFeatures extends TableFeatures, TData extends RowData, > { @@ -272,28 +259,27 @@ export interface Table_ColumnFiltering< * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) */ getPreFilteredRowModel: () => RowModel +} + +export interface CreateRowModel_Filtered< + TFeatures extends TableFeatures, + TData extends RowData, +> { /** - * Resets the **columnFilters** state to `initialState.columnFilters`, or `true` can be passed to force a default blank state reset to `[]`. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#resetcolumnfilters) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) - */ - resetColumnFilters: (defaultState?: boolean) => void - /** - * Resets the **globalFilter** state to `initialState.globalFilter`, or `true` can be passed to force a default blank state reset to `undefined`. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#resetglobalfilter) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) - */ - resetGlobalFilter: (defaultState?: boolean) => void - /** - * Sets or updates the `state.columnFilters` state. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#setcolumnfilters) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) - */ - setColumnFilters: (updater: Updater) => void - /** - * Sets or updates the `state.globalFilter` state. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#setglobalfilter) + * If provided, this function is called **once** per table and should return a **new function** which will calculate and return the row model for the table when it's filtered. + * - For server-side filtering, this function is unnecessary and can be ignored since the server should already return the filtered row model. + * - For client-side filtering, this function is required. A default implementation is provided via any table adapter's `{ getFilteredRowModel }` export. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfilteredrowmodel) * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) */ - setGlobalFilter: (updater: Updater) => void + filteredRowModel?: ( + table: Table, + ) => () => RowModel +} + +export interface CachedRowModel_Filtered< + TFeatures extends TableFeatures, + TData extends RowData, +> { + filteredRowModel: () => RowModel } diff --git a/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts b/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts index e93c1ff80d..18956d6d7d 100644 --- a/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts +++ b/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts @@ -1,12 +1,8 @@ import { functionalUpdate, isFunction } from '../../utils' import { row_getValue } from '../../core/rows/Rows.utils' -import { - table_getCoreRowModel, - table_getState, -} from '../../core/table/Tables.utils' +import { table_getState } from '../../core/table/Tables.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' import type { Table_Internal } from '../../types/Table' import type { Column } from '../../types/Column' import type { @@ -31,7 +27,7 @@ export function column_getAutoFilterFn< | Record> | undefined - const firstRow = table_getCoreRowModel(table).flatRows[0] + const firstRow = table.getCoreRowModel().flatRows[0] const value = firstRow ? row_getValue(firstRow, table, column.id) : undefined @@ -220,28 +216,6 @@ export function table_resetColumnFilters< ) } -export function table_getPreFilteredRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal) { - return table_getCoreRowModel(table) -} - -export function table_getFilteredRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.Filtered) { - table._rowModels.Filtered = table.options._rowModels?.Filtered?.(table) - } - - if (table.options.manualFiltering || !table._rowModels.Filtered) { - return table_getPreFilteredRowModel(table) - } - - return table._rowModels.Filtered() -} - export function shouldAutoRemoveFilter< TFeatures extends TableFeatures, TData extends RowData, diff --git a/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts b/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts index d8fcd897fe..38e314eabc 100644 --- a/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts +++ b/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts @@ -7,13 +7,10 @@ import { import { table_getState } from '../../core/table/Tables.utils' import { table_autoResetPageIndex } from '../row-pagination/RowPagination.utils' import { filterRows } from './filterRowsUtils' -import { - column_getFilterFn, - table_getPreFilteredRowModel, -} from './ColumnFiltering.utils' +import { column_getFilterFn } from './ColumnFiltering.utils' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' import type { @@ -28,9 +25,9 @@ export function createFilteredRowModel< return (table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), - fnName: 'table.createFilteredRowModel', + fnName: 'table.getFilteredRowModel', memoDeps: () => [ - table_getPreFilteredRowModel(table), + table.getPreFilteredRowModel(), table_getState(table).columnFilters, table_getState(table).globalFilter, ], @@ -43,10 +40,10 @@ function _createFilteredRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table): RowModel { - const rowModel = table_getPreFilteredRowModel(table) + const rowModel = table.getPreFilteredRowModel() const { columnFilters, globalFilter } = table_getState(table) - if (!rowModel.rows.length || (!columnFilters.length && !globalFilter)) { + if (!rowModel.rows.length || (!columnFilters?.length && !globalFilter)) { for (const row of rowModel.flatRows) { row.columnFilters = {} row.columnFiltersMeta = {} diff --git a/packages/table-core/src/features/column-filtering/filterRowsUtils.ts b/packages/table-core/src/features/column-filtering/filterRowsUtils.ts index c9848bbc6b..78c25b9b19 100644 --- a/packages/table-core/src/features/column-filtering/filterRowsUtils.ts +++ b/packages/table-core/src/features/column-filtering/filterRowsUtils.ts @@ -5,7 +5,7 @@ import type { } from './ColumnFiltering.types' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' diff --git a/packages/table-core/src/features/column-grouping/ColumnGrouping.ts b/packages/table-core/src/features/column-grouping/ColumnGrouping.ts index b9d404f79a..fb22d2c613 100644 --- a/packages/table-core/src/features/column-grouping/ColumnGrouping.ts +++ b/packages/table-core/src/features/column-grouping/ColumnGrouping.ts @@ -13,8 +13,6 @@ import { getDefaultGroupingState, row_getGroupingValue, row_getIsGrouped, - table_getGroupedRowModel, - table_getPreGroupedRowModel, table_resetGrouping, table_setGrouping, } from './ColumnGrouping.utils' @@ -22,7 +20,7 @@ import type { TableState } from '../../types/TableState' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' -import type { Row } from '../../types/Row' +import type { Row_Internal } from '../../types/Row' import type { Cell } from '../../types/Cell' import type { Column } from '../../types/Column' import type { @@ -132,9 +130,8 @@ export const ColumnGrouping: TableFeature = { }, constructRow: ( - row: Row & Partial, - table: Table & - Partial>, + row: Row_Internal, + table: Table, ): void => { row._groupingValuesCache = {} @@ -159,12 +156,6 @@ export const ColumnGrouping: TableFeature = { { fn: (defaultState) => table_resetGrouping(table, defaultState), }, - { - fn: () => table_getPreGroupedRowModel(table), - }, - { - fn: () => table_getGroupedRowModel(table), - }, ]) }, } diff --git a/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts b/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts index 38cb6e971a..f9ca9a1a7e 100644 --- a/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts +++ b/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts @@ -1,3 +1,5 @@ +import type { RowModel } from '../../core/row-models/RowModels.types' +import type { Table } from '../../types/Table' import type { BuiltInAggregationFn } from '../../fns/aggregationFns' import type { CellData, @@ -6,7 +8,6 @@ import type { Updater, } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' import type { Row } from '../../types/Row' import type { Cell } from '../../types/Cell' import type { ColumnDefTemplate } from '../../types/ColumnDef' @@ -89,31 +90,6 @@ export interface ColumnDef_ColumnGrouping< getGroupingValue?: (row: TData) => any } -export interface ColumnDef_ColumnGrouping_Unavailable< - TFeatures extends TableFeatures, - TData extends RowData, - TValue extends CellData = CellData, -> { - /** - * @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs. - */ - aggregatedCell?: ColumnDefTemplate< - ReturnType['getContext']> - > - /** - * @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs. - */ - aggregationFn?: AggregationFnOption - /** - * @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs. - */ - enableGrouping?: boolean - /** - * @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs. - */ - getGroupingValue?: (row: TData) => any -} - export interface Column_ColumnGrouping< TFeatures extends TableFeatures, TData extends RowData, @@ -243,28 +219,27 @@ export interface TableOptions_ColumnGrouping { onGroupingChange?: OnChangeFn } -export interface TableOptions_ColumnGrouping_Unavailable { - /** - * @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs. - */ - enableGrouping?: boolean - /** - * @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs. - */ - groupedColumnMode?: false | 'reorder' | 'remove' +export type GroupingColumnMode = false | 'reorder' | 'remove' + +export interface Table_ColumnGrouping< + TFeatures extends TableFeatures, + TData extends RowData, +> { /** - * @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs. + * Resets the **grouping** state to `initialState.grouping`, or `true` can be passed to force a default blank state reset to `[]`. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#resetgrouping) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping) */ - manualGrouping?: boolean + resetGrouping: (defaultState?: boolean) => void /** - * @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs. + * Updates the grouping state of the table via an update function or value. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#setgrouping) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping) */ - onGroupingChange?: OnChangeFn + setGrouping: (updater: Updater) => void } -export type GroupingColumnMode = false | 'reorder' | 'remove' - -export interface Table_ColumnGrouping< +export interface Table_RowModels_Grouped< TFeatures extends TableFeatures, TData extends RowData, > { @@ -280,16 +255,25 @@ export interface Table_ColumnGrouping< * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping) */ getPreGroupedRowModel: () => RowModel +} + +export interface CreateRowModel_Grouped< + TFeatures extends TableFeatures, + TData extends RowData, +> { /** - * Resets the **grouping** state to `initialState.grouping`, or `true` can be passed to force a default blank state reset to `[]`. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#resetgrouping) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping) - */ - resetGrouping: (defaultState?: boolean) => void - /** - * Updates the grouping state of the table via an update function or value. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#setgrouping) + * Returns the row model after grouping has taken place, but no further. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupedrowmodel) * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping) */ - setGrouping: (updater: Updater) => void + groupedRowModel?: ( + table: Table, + ) => () => RowModel +} + +export interface CachedRowModel_Grouped< + TFeatures extends TableFeatures, + TData extends RowData, +> { + groupedRowModel: () => RowModel } diff --git a/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts b/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts index 1f96b5ab97..e0f3ab625f 100644 --- a/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts +++ b/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts @@ -1,5 +1,4 @@ import { isFunction } from '../../utils' -import { table_getFilteredRowModel } from '../column-filtering/ColumnFiltering.utils' import { table_getInitialState, table_getState, @@ -7,7 +6,7 @@ import { import { table_getColumn } from '../../core/columns/Columns.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' import type { Cell } from '../../types/Cell' @@ -167,27 +166,7 @@ export function table_resetGrouping< ) } -export function table_getPreGroupedRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - return table_getFilteredRowModel(table) -} - -export function table_getGroupedRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.Grouped) { - table._rowModels.Grouped = table.options._rowModels?.Grouped?.(table) - } - if (table.options.manualGrouping || !table._rowModels.Grouped) { - return table_getPreGroupedRowModel(table) - } - - return table._rowModels.Grouped() -} export function row_getIsGrouped< TFeatures extends TableFeatures, diff --git a/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts b/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts index 4f0b30a99c..a2e2d473b1 100644 --- a/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts +++ b/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts @@ -4,13 +4,10 @@ import { table_getColumn } from '../../core/columns/Columns.utils' import { table_getState } from '../../core/table/Tables.utils' import { table_autoResetExpanded } from '../row-expanding/RowExpanding.utils' import { table_autoResetPageIndex } from '../row-pagination/RowPagination.utils' -import { - row_getGroupingValue, - table_getPreGroupedRowModel, -} from './ColumnGrouping.utils' +import { row_getGroupingValue } from './ColumnGrouping.utils' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' @@ -21,10 +18,10 @@ export function createGroupedRowModel< return (table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), - fnName: 'table.createGroupedRowModel', + fnName: 'table.getGroupedRowModel', memoDeps: () => [ table_getState(table).grouping, - table_getPreGroupedRowModel(table), + table.getPreGroupedRowModel(), ], fn: () => _createGroupedRowModel(table), onAfterUpdate: () => { @@ -38,7 +35,7 @@ function _createGroupedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table): RowModel { - const rowModel = table_getPreGroupedRowModel(table) + const rowModel = table.getPreGroupedRowModel() const grouping = table_getState(table).grouping if (!rowModel.rows.length || !grouping?.length) { diff --git a/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts b/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts index 08fce14559..9767a39d69 100644 --- a/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts +++ b/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts @@ -24,13 +24,6 @@ export interface TableOptions_ColumnOrdering { onColumnOrderChange?: OnChangeFn } -export interface TableOptions_ColumnOrdering_Unavailable { - /** - * @deprecated Import the `ColumnOrdering` feature to use the column ordering APIs. - */ - onColumnOrderChange?: OnChangeFn -} - export interface Column_ColumnOrdering { /** * Returns the index of the column in the order of the visible columns. Optionally pass a `position` parameter to get the index of the column in a sub-section of the table diff --git a/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts b/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts index 68cfa35b81..9634071a36 100644 --- a/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts +++ b/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts @@ -38,17 +38,6 @@ export interface TableOptions_ColumnPinning { onColumnPinningChange?: OnChangeFn } -export interface TableOptions_ColumnPinning_Unavailable { - /** - * @deprecated Import the `ColumnPinning` feature to use the column pinning APIs. - */ - enableColumnPinning?: boolean - /** - * @deprecated Import the `ColumnPinning` feature to use the column pinning APIs. - */ - onColumnPinningChange?: OnChangeFn -} - export interface ColumnPinningDefaultOptions { onColumnPinningChange: OnChangeFn } @@ -62,13 +51,6 @@ export interface ColumnDef_ColumnPinning { enablePinning?: boolean } -export interface ColumnDef_ColumnPinning_Unavailable { - /** - * @deprecated Import the `ColumnPinning` feature to use the column pinning APIs. - */ - enablePinning?: boolean -} - export interface Column_ColumnPinning { /** * Returns whether or not the column can be pinned. diff --git a/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts b/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts index af24bd8432..f3653a78b3 100644 --- a/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts +++ b/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts @@ -51,25 +51,6 @@ export interface TableOptions_ColumnResizing { onColumnResizingChange?: OnChangeFn } -export interface TableOptions_ColumnResizing_Unavailable { - /** - * @deprecated Import the `ColumnResizing` feature to use the column resizing APIs. - */ - columnResizeMode?: ColumnResizeMode - /** - * @deprecated Import the `ColumnResizing` feature to use the column resizing APIs. - */ - enableColumnResizing?: boolean - /** - * @deprecated Import the `ColumnResizing` feature to use the column resizing APIs. - */ - columnResizeDirection?: ColumnResizeDirection - /** - * @deprecated Import the `ColumnResizing` feature to use the column resizing APIs. - */ - oncolumnResizingChange?: OnChangeFn -} - export type ColumnResizingDefaultOptions = Pick< TableOptions_ColumnResizing, 'columnResizeMode' | 'onColumnResizingChange' | 'columnResizeDirection' @@ -99,13 +80,6 @@ export interface ColumnDef_ColumnResizing { enableResizing?: boolean } -export interface ColumnDef_ColumnResizing_Unavailable { - /** - * @deprecated Import the `ColumnResizing` feature to use the column resizing APIs. - */ - enableResizing?: boolean -} - export interface Column_ColumnResizing { /** * Returns `true` if the column can be resized. diff --git a/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts b/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts index 0fd21425a6..a6f040b48b 100644 --- a/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts +++ b/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts @@ -23,13 +23,6 @@ export interface TableOptions_ColumnSizing { onColumnSizingChange?: OnChangeFn } -export interface TableOptions_ColumnSizing_Unavailable { - /** - * @deprecated Import the `ColumnSizing` feature to use the column sizing APIs. - */ - onColumnSizingChange?: OnChangeFn -} - export type ColumnSizingDefaultOptions = Pick< TableOptions_ColumnSizing, 'onColumnSizingChange' @@ -95,21 +88,6 @@ export interface ColumnDef_ColumnSizing { size?: number } -export interface ColumnDef_ColumnSizing_Unavailable { - /** - * @deprecated Import the `ColumnSizing` feature to use the column sizing APIs. - */ - maxSize?: number - /** - * @deprecated Import the `ColumnSizing` feature to use the column sizing APIs. - */ - minSize?: number - /** - * @deprecated Import the `ColumnSizing` feature to use the column sizing APIs. - */ - size?: number -} - export interface Column_ColumnSizing { /** * Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the header. This is effectively a sum of the offset measurements of all succeeding (right) headers in relation to the current column. diff --git a/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts b/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts index 7528492354..cfbe438c12 100644 --- a/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts +++ b/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts @@ -31,17 +31,6 @@ export interface TableOptions_ColumnVisibility { onColumnVisibilityChange?: OnChangeFn } -export interface TableOptions_ColumnVisibility_Unavailable { - /** - * @deprecated Import the `ColumnVisibility` feature to use the column visibility APIs. - */ - enableHiding?: boolean - /** - * @deprecated Import the `ColumnVisibility` feature to use the column visibility APIs. - */ - onColumnVisibilityChange?: OnChangeFn -} - export type VisibilityDefaultOptions = Pick< TableOptions_ColumnVisibility, 'onColumnVisibilityChange' @@ -110,13 +99,6 @@ export interface ColumnDef_ColumnVisibility { enableHiding?: boolean } -export interface ColumnDef_ColumnVisibility_Unavailable { - /** - * @deprecated Import the `ColumnVisibility` feature to use the column visibility APIs. - */ - enableHiding?: boolean -} - export interface Row_ColumnVisibility< TFeatures extends TableFeatures, TData extends RowData, diff --git a/packages/table-core/src/features/global-faceting/GlobalFaceting.types.ts b/packages/table-core/src/features/global-faceting/GlobalFaceting.types.ts index 5cdb7582ae..dfe6aada5f 100644 --- a/packages/table-core/src/features/global-faceting/GlobalFaceting.types.ts +++ b/packages/table-core/src/features/global-faceting/GlobalFaceting.types.ts @@ -1,6 +1,6 @@ import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' export interface Table_GlobalFaceting< TFeatures extends TableFeatures, diff --git a/packages/table-core/src/features/global-faceting/GlobalFaceting.utils.ts b/packages/table-core/src/features/global-faceting/GlobalFaceting.utils.ts index f2d2c7bef3..dc1a676f7b 100644 --- a/packages/table-core/src/features/global-faceting/GlobalFaceting.utils.ts +++ b/packages/table-core/src/features/global-faceting/GlobalFaceting.utils.ts @@ -1,7 +1,6 @@ -import { table_getPreFilteredRowModel } from '../column-filtering/ColumnFiltering.utils' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table_Internal } from '../../types/Table' /** @@ -14,7 +13,7 @@ export function table_getGlobalFacetedMinMaxValues< TData extends RowData, >(table: Table_Internal): () => undefined | [number, number] { return ( - table.options._rowModels?.FacetedMinMax?.(table, '__global__') ?? + table.options._rowModels?.facetedMinMaxValues?.(table, '__global__') ?? (() => undefined) ) } @@ -29,8 +28,8 @@ export function table_getGlobalFacetedRowModel< TData extends RowData, >(table: Table_Internal): () => RowModel { return ( - table.options._rowModels?.Faceted?.(table, '__global__') ?? - (() => table_getPreFilteredRowModel(table)) + table.options._rowModels?.facetedRowModel?.(table, '__global__') ?? + (() => table.getPreFilteredRowModel()) ) } @@ -44,7 +43,7 @@ export function table_getGlobalFacetedUniqueValues< TData extends RowData, >(table: Table_Internal): () => Map { return ( - table.options._rowModels?.FacetedUnique?.(table, '__global__') ?? + table.options._rowModels?.facetedUniqueValues?.(table, '__global__') ?? (() => new Map()) ) } diff --git a/packages/table-core/src/features/global-filtering/GlobalFiltering.ts b/packages/table-core/src/features/global-filtering/GlobalFiltering.ts index aa64d37d29..916de57555 100644 --- a/packages/table-core/src/features/global-filtering/GlobalFiltering.ts +++ b/packages/table-core/src/features/global-filtering/GlobalFiltering.ts @@ -1,5 +1,4 @@ import { assignAPIs, makeStateUpdater } from '../../utils' -import { table_getCoreRowModel } from '../../core/table/Tables.utils' import { column_getCanGlobalFilter, table_getGlobalAutoFilterFn, @@ -47,7 +46,7 @@ export const GlobalFiltering: TableFeature = { onGlobalFilterChange: makeStateUpdater('globalFilter', table), globalFilterFn: 'auto', getColumnCanGlobalFilter: (column) => { - const value = table_getCoreRowModel(table as Table) + const value = table.getCoreRowModel() .flatRows[0]?.getAllCellsByColumnId() [column.id]?.getValue() diff --git a/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts b/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts index 0f0d19edcf..3dd87c8fbd 100644 --- a/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts +++ b/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts @@ -31,13 +31,6 @@ export interface ColumnDef_GlobalFiltering { enableGlobalFilter?: boolean } -export interface ColumnDef_GlobalFiltering_Unavailable { - /** - * @deprecated Import the `GlobalFiltering` feature to use the global filtering APIs. - */ - enableGlobalFilter?: boolean -} - export interface Column_GlobalFiltering { /** * Returns whether or not the column can be **globally** filtered. Set to `false` to disable a column from being scanned during global filtering. @@ -88,34 +81,6 @@ export interface TableOptions_GlobalFiltering< onGlobalFilterChange?: OnChangeFn } -export interface TableOptions_GlobalFiltering_Unavailable< - TFeatures extends TableFeatures, - TData extends RowData, -> { - /** - * @deprecated Import the `GlobalFiltering` feature to use the global filtering APIs. - */ - enableGlobalFilter?: boolean - /** - * @deprecated Import the `GlobalFiltering` feature to use the global filtering APIs. - */ - getColumnCanGlobalFilter?: < - TFeatures extends TableFeatures, - TData extends RowData, - TValue extends CellData = CellData, - >( - column: Column, - ) => boolean - /** - * @deprecated Import the `GlobalFiltering` feature to use the global filtering APIs. - */ - globalFilterFn?: FilterFnOption - /** - * @deprecated Import the `GlobalFiltering` feature to use the global filtering APIs. - */ - onGlobalFilterChange?: OnChangeFn -} - export interface Table_GlobalFiltering< TFeatures extends TableFeatures, TData extends RowData, diff --git a/packages/table-core/src/features/row-expanding/RowExpanding.ts b/packages/table-core/src/features/row-expanding/RowExpanding.ts index 456dd1f439..9d825f43ea 100644 --- a/packages/table-core/src/features/row-expanding/RowExpanding.ts +++ b/packages/table-core/src/features/row-expanding/RowExpanding.ts @@ -9,10 +9,8 @@ import { table_autoResetExpanded, table_getCanSomeRowsExpand, table_getExpandedDepth, - table_getExpandedRowModel, table_getIsAllRowsExpanded, table_getIsSomeRowsExpanded, - table_getPreExpandedRowModel, table_getToggleAllRowsExpandedHandler, table_resetExpanded, table_setExpanded, @@ -113,12 +111,6 @@ export const RowExpanding: TableFeature = { { fn: () => table_getExpandedDepth(table), }, - { - fn: () => table_getPreExpandedRowModel(table), - }, - { - fn: () => table_getExpandedRowModel(table), - }, ]) }, } diff --git a/packages/table-core/src/features/row-expanding/RowExpanding.types.ts b/packages/table-core/src/features/row-expanding/RowExpanding.types.ts index 89cbbe83e1..edfd038379 100644 --- a/packages/table-core/src/features/row-expanding/RowExpanding.types.ts +++ b/packages/table-core/src/features/row-expanding/RowExpanding.types.ts @@ -1,6 +1,7 @@ +import type { Table } from '../../types/Table' import type { OnChangeFn, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Row } from '../../types/Row' export type ExpandedStateList = Record @@ -98,45 +99,11 @@ export interface TableOptions_RowExpanding< paginateExpandedRows?: boolean } -export interface TableOptions_RowExpanding_Unavailable< - TFeatures extends TableFeatures, - TData extends RowData, -> { - /** - * @deprecated Import the `RowExpanding` feature to use the row expanding APIs. - */ - autoResetExpanded?: boolean - /** - * @deprecated Import the `RowExpanding` feature to use the row expanding APIs. - */ - enableExpanding?: boolean - /** - * @deprecated Import the `RowExpanding` feature to use the row expanding APIs. - */ - getIsRowExpanded?: (row: Row) => boolean - /** - * @deprecated Import the `RowExpanding` feature to use the row expanding APIs. - */ - getRowCanExpand?: (row: Row) => boolean - /** - * @deprecated Import the `RowExpanding` feature to use the row expanding APIs. - */ - manualExpanding?: boolean - /** - * @deprecated Import the `RowExpanding` feature to use the row expanding APIs. - */ - onExpandedChange?: OnChangeFn - /** - * @deprecated Import the `RowExpanding` feature to use the row expanding APIs. - */ - paginateExpandedRows?: boolean -} - export interface Table_RowExpanding< TFeatures extends TableFeatures, TData extends RowData, > { - _autoResetExpanded: () => void + autoResetExpanded: () => void /** * Returns whether there are any rows that can be expanded. * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getcansomerowsexpand) @@ -149,12 +116,6 @@ export interface Table_RowExpanding< * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding) */ getExpandedDepth: () => number - /** - * Returns the row model after expansion has been applied. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getexpandedrowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding) - */ - getExpandedRowModel: () => RowModel /** * Returns whether all rows are currently expanded. * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getisallrowsexpanded) @@ -167,12 +128,6 @@ export interface Table_RowExpanding< * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding) */ getIsSomeRowsExpanded: () => boolean - /** - * Returns the row model before expansion has been applied. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getpreexpandedrowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding) - */ - getPreExpandedRowModel: () => RowModel /** * Returns a handler that can be used to toggle the expanded state of all rows. This handler is meant to be used with an `input[type=checkbox]` element. * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#gettoggleallrowsexpandedhandler) @@ -198,3 +153,42 @@ export interface Table_RowExpanding< */ toggleAllRowsExpanded: (expanded?: boolean) => void } + +export interface Table_RowModels_Expanded< + TFeatures extends TableFeatures, + TData extends RowData, +> { + /** + * Returns the row model after expansion has been applied. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getexpandedrowmodel) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding) + */ + getExpandedRowModel: () => RowModel + /** + * Returns the row model before expansion has been applied. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getpreexpandedrowmodel) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding) + */ + getPreExpandedRowModel: () => RowModel +} + +export interface CreateRowModel_Expanded< + TFeatures extends TableFeatures, + TData extends RowData, +> { + /** + * This function is responsible for returning the expanded row model. If this function is not provided, the table will not expand rows. You can use the default exported `getExpandedRowModel` function to get the expanded row model or implement your own. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getexpandedrowmodel) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding) + */ + expandedRowModel?: ( + table: Table, + ) => () => RowModel +} + +export interface CachedRowModel_Expanded< + TFeatures extends TableFeatures, + TData extends RowData, +> { + expandedRowModel: () => RowModel +} diff --git a/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts b/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts index 35926cdab2..52f05370cd 100644 --- a/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts +++ b/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts @@ -1,14 +1,10 @@ -import { table_getPrePaginationRowModel } from '../row-pagination/RowPagination.utils' -import { table_getSortedRowModel } from '../row-sorting/RowSorting.utils' import { table_getRow } from '../../core/rows/Rows.utils' import { table_getInitialState, - table_getRowModel, table_getState, } from '../../core/table/Tables.utils' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' import type { ExpandedState, ExpandedStateList } from './RowExpanding.types' @@ -27,29 +23,13 @@ export function getDefaultExpandedState(): ExpandedState { export function table_autoResetExpanded< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - registered?: boolean, - queued?: boolean, -) { - if (!registered) { - table._queue(() => { - registered = true - }) - return - } - +>(table: Table_Internal) { if ( table.options.autoResetAll ?? table.options.autoResetExpanded ?? !table.options.manualExpanding ) { - if (queued) return - queued = true - table._queue(() => { - table_resetExpanded(table) - queued = false - }) + queueMicrotask(() => table_resetExpanded(table)) } } @@ -105,9 +85,9 @@ export function table_getCanSomeRowsExpand< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - return table_getPrePaginationRowModel(table).flatRows.some((row) => - row_getCanExpand(row, table), - ) + return table + .getPrePaginatedRowModel() + .flatRows.some((row) => row_getCanExpand(row, table)) } /** @@ -160,9 +140,7 @@ export function table_getIsAllRowsExpanded< // If any row is not expanded, return false if ( - table_getRowModel(table).flatRows.some( - (row) => !row_getIsExpanded(row, table), - ) + table.getRowModel().flatRows.some((row) => !row_getIsExpanded(row, table)) ) { return false } @@ -184,7 +162,7 @@ export function table_getExpandedDepth< const rowIds = table_getState(table).expanded === true - ? Object.keys(table_getRowModel(table).rowsById) + ? Object.keys(table.getRowModel().rowsById) : Object.keys(table_getState(table).expanded ?? {}) rowIds.forEach((id) => { @@ -195,38 +173,6 @@ export function table_getExpandedDepth< return maxDepth } -/** - * - * @param table - * @returns - */ -export function table_getPreExpandedRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - return table_getSortedRowModel(table) -} - -/** - * - * @param table - * @returns - */ -export function table_getExpandedRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.Expanded) { - table._rowModels.Expanded = table.options._rowModels?.Expanded?.(table) - } - - if (table.options.manualExpanding || !table._rowModels.Expanded) { - return table_getPreExpandedRowModel(table) - } - - return table._rowModels.Expanded() -} - /** * * @param row @@ -247,7 +193,7 @@ export function row_toggleExpanded< let oldExpanded: ExpandedStateList = {} if (old === true) { - Object.keys(table_getRowModel(table).rowsById).forEach((rowId) => { + Object.keys(table.getRowModel().rowsById).forEach((rowId) => { oldExpanded[rowId] = true }) } else { diff --git a/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts b/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts index ec5e648166..f1ba8093dc 100644 --- a/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts +++ b/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts @@ -1,12 +1,9 @@ import { isDev, tableMemo } from '../../utils' import { table_getState } from '../../core/table/Tables.utils' -import { - row_getIsExpanded, - table_getPreExpandedRowModel, -} from './RowExpanding.utils' +import { row_getIsExpanded } from './RowExpanding.utils' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table, Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' @@ -19,10 +16,10 @@ export function createExpandedRowModel< return (table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), - fnName: 'table.createExpandedRowModel', + fnName: 'table.getExpandedRowModel', memoDeps: () => [ table_getState(table).expanded, - table_getPreExpandedRowModel(table), + table.getPreExpandedRowModel(), table.options.paginateExpandedRows, ], fn: () => _createExpandedRowModel(table), @@ -33,7 +30,7 @@ export function _createExpandedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal): RowModel { - const rowModel = table_getPreExpandedRowModel(table) + const rowModel = table.getPreExpandedRowModel() const expanded = table_getState(table).expanded if ( diff --git a/packages/table-core/src/features/row-pagination/RowPagination.ts b/packages/table-core/src/features/row-pagination/RowPagination.ts index 5e45e8f041..ade6f0cc2e 100644 --- a/packages/table-core/src/features/row-pagination/RowPagination.ts +++ b/packages/table-core/src/features/row-pagination/RowPagination.ts @@ -7,8 +7,6 @@ import { table_getCanPreviousPage, table_getPageCount, table_getPageOptions, - table_getPaginatedRowModel, - table_getPrePaginationRowModel, table_getRowCount, table_lastPage, table_nextPage, @@ -111,12 +109,6 @@ export const RowPagination: TableFeature = { { fn: () => table_lastPage(table), }, - { - fn: () => table_getPrePaginationRowModel(table), - }, - { - fn: () => table_getPaginatedRowModel(table), - }, { fn: () => table_getPageCount(table), }, diff --git a/packages/table-core/src/features/row-pagination/RowPagination.types.ts b/packages/table-core/src/features/row-pagination/RowPagination.types.ts index d17ee8e5be..a1c199720d 100644 --- a/packages/table-core/src/features/row-pagination/RowPagination.types.ts +++ b/packages/table-core/src/features/row-pagination/RowPagination.types.ts @@ -1,6 +1,7 @@ +import type { RowModel } from '../../core/row-models/RowModels.types' +import type { Table } from '../../types/Table' import type { OnChangeFn, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' export interface PaginationState { pageIndex: number @@ -50,29 +51,6 @@ export interface TableOptions_RowPagination { rowCount?: number } -export interface TableOptions_RowPagination_Unavailable { - /** - * @deprecated Import the `RowPagination` feature to use the row pagination APIs. - */ - autoResetPageIndex?: boolean - /** - * @deprecated Import the `RowPagination` feature to use the row pagination APIs. - */ - manualPagination?: boolean - /** - * @deprecated Import the `RowPagination` feature to use the row pagination APIs. - */ - onPaginationChange?: OnChangeFn - /** - * @deprecated Import the `RowPagination` feature to use the row pagination APIs. - */ - pageCount?: number - /** - * @deprecated Import the `RowPagination` feature to use the row pagination APIs. - */ - rowCount?: number -} - export interface PaginationDefaultOptions { onPaginationChange: OnChangeFn } @@ -112,18 +90,6 @@ export interface Table_RowPagination< * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination) */ getPageOptions: () => Array - /** - * Returns the row model for the table after pagination has been applied. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getPaginatedRowModel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination) - */ - getPaginatedRowModel: () => RowModel - /** - * Returns the row model for the table before any pagination has been applied. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getprepaginationrowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination) - */ - getPrePaginationRowModel: () => RowModel /** * Increments the page index by one, if possible. * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#nextpage) @@ -185,3 +151,44 @@ export interface Table_RowPagination< */ setPagination: (updater: Updater) => void } + +export interface Table_RowModels_Paginated< + TFeatures extends TableFeatures, + TData extends RowData, +> { + /** + * Returns the row model for the table after pagination has been applied. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getPaginatedRowModel) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination) + */ + getPaginatedRowModel: () => RowModel + /** + * Returns the row model for the table before any pagination has been applied. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getprepaginationrowmodel) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination) + */ + getPrePaginatedRowModel: () => RowModel +} + +export interface CreateRowModel_Paginated< + TFeatures extends TableFeatures, + TData extends RowData, +> { + /** + * Returns the row model after pagination has taken place, but no further. + * + * Pagination columns are automatically reordered by default to the start of the columns list. If you would rather remove them or leave them as-is, set the appropriate mode here. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getPaginatedRowModel) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination) + */ + paginatedRowModel?: ( + table: Table, + ) => () => RowModel +} + +export interface CachedRowModel_Paginated< + TFeatures extends TableFeatures, + TData extends RowData, +> { + paginatedRowModel: () => RowModel +} diff --git a/packages/table-core/src/features/row-pagination/RowPagination.utils.ts b/packages/table-core/src/features/row-pagination/RowPagination.utils.ts index 9082f3102f..153fbf00f6 100644 --- a/packages/table-core/src/features/row-pagination/RowPagination.utils.ts +++ b/packages/table-core/src/features/row-pagination/RowPagination.utils.ts @@ -1,12 +1,10 @@ import { functionalUpdate } from '../../utils' -import { table_getExpandedRowModel } from '../row-expanding/RowExpanding.utils' import { table_getInitialState, table_getState, } from '../../core/table/Tables.utils' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' import type { Table_Internal } from '../../types/Table' import type { PaginationState } from './RowPagination.types' @@ -269,38 +267,6 @@ export function table_lastPage< return table_setPageIndex(table, table_getPageCount(table) - 1) } -/** - * - * @param table - * @returns - */ -export function table_getPrePaginationRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - return table_getExpandedRowModel(table) -} - -/** - * - * @param table - * @returns - */ -export function table_getPaginatedRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.Paginated) { - table._rowModels.Paginated = table.options._rowModels?.Paginated?.(table) - } - - if (table.options.manualPagination || !table._rowModels.Paginated) { - return table_getPrePaginationRowModel(table) - } - - return table._rowModels.Paginated() -} - /** * * @param table @@ -328,7 +294,5 @@ export function table_getRowCount< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - return ( - table.options.rowCount ?? table_getPrePaginationRowModel(table).rows.length - ) + return table.options.rowCount ?? table.getPrePaginatedRowModel().rows.length } diff --git a/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts b/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts index f043bd0543..da36508156 100644 --- a/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts +++ b/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts @@ -1,13 +1,10 @@ import { isDev, tableMemo } from '../../utils' import { expandRows } from '../row-expanding/createExpandedRowModel' import { table_getState } from '../../core/table/Tables.utils' -import { - getDefaultPaginationState, - table_getPrePaginationRowModel, -} from './RowPagination.utils' +import { getDefaultPaginationState } from './RowPagination.utils' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' @@ -20,9 +17,9 @@ export function createPaginatedRowModel< return (table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), - fnName: 'table.createPaginatedRowModel', + fnName: 'table.getPaginatedRowModel', memoDeps: () => [ - table_getPrePaginationRowModel(table), + table.getPrePaginatedRowModel(), table_getState(table).pagination, table.options.paginateExpandedRows ? table_getState(table).expanded @@ -36,7 +33,7 @@ function _createPaginatedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal): RowModel { - const prePaginatedRowModel = table_getPrePaginationRowModel(table) + const prePaginatedRowModel = table.getPrePaginatedRowModel() const pagination = table_getState(table).pagination if (!prePaginatedRowModel.rows.length) { diff --git a/packages/table-core/src/features/row-pinning/RowPinning.types.ts b/packages/table-core/src/features/row-pinning/RowPinning.types.ts index d9f567d1d0..7c3bfee851 100644 --- a/packages/table-core/src/features/row-pinning/RowPinning.types.ts +++ b/packages/table-core/src/features/row-pinning/RowPinning.types.ts @@ -44,24 +44,6 @@ export interface TableOptions_RowPinning< onRowPinningChange?: OnChangeFn } -export interface TableOptions_RowPinning_Unavailable< - TFeatures extends TableFeatures, - TData extends RowData, -> { - /** - * @deprecated Import the `RowPinning` feature to use the row pinning APIs. - */ - enableRowPinning?: boolean | ((row: Row) => boolean) - /** - * @deprecated Import the `RowPinning` feature to use the row pinning APIs. - */ - keepPinnedRows?: boolean - /** - * @deprecated Import the `RowPinning` feature to use the row pinning APIs. - */ - onRowPinningChange?: OnChangeFn -} - export interface RowPinningDefaultOptions { onRowPinningChange: OnChangeFn } diff --git a/packages/table-core/src/features/row-pinning/RowPinning.utils.ts b/packages/table-core/src/features/row-pinning/RowPinning.utils.ts index 3187a459e7..de6ca5196d 100644 --- a/packages/table-core/src/features/row-pinning/RowPinning.utils.ts +++ b/packages/table-core/src/features/row-pinning/RowPinning.utils.ts @@ -236,7 +236,6 @@ export function row_pin( includeLeafRows?: boolean, includeParentRows?: boolean, ): void { - console.log('pinning row', row.id) const leafRowIds = includeLeafRows ? row_getLeafRows(row).map(({ id }) => id) : [] diff --git a/packages/table-core/src/features/row-selection/RowSelection.ts b/packages/table-core/src/features/row-selection/RowSelection.ts index 3ed2a2454d..f220cda613 100644 --- a/packages/table-core/src/features/row-selection/RowSelection.ts +++ b/packages/table-core/src/features/row-selection/RowSelection.ts @@ -1,7 +1,5 @@ import { assignAPIs, makeStateUpdater } from '../../utils' import { table_getState } from '../../core/table/Tables.utils' -import { table_getFilteredRowModel } from '../column-filtering/ColumnFiltering.utils' -import { table_getSortedRowModel } from '../row-sorting/RowSorting.utils' import { getDefaultRowSelectionState, row_getCanMultiSelect, @@ -137,14 +135,14 @@ export const RowSelection: TableFeature = { fn: () => table_getFilteredSelectedRowModel(table), memoDeps: () => [ table_getState(table).rowSelection, - table_getFilteredRowModel(table), + table.getFilteredRowModel(), ], }, { fn: () => table_getGroupedSelectedRowModel(table), memoDeps: () => [ table_getState(table).rowSelection, - table_getSortedRowModel(table), + table.getSortedRowModel(), ], }, { diff --git a/packages/table-core/src/features/row-selection/RowSelection.types.ts b/packages/table-core/src/features/row-selection/RowSelection.types.ts index 45a63d70fb..3618d536c5 100644 --- a/packages/table-core/src/features/row-selection/RowSelection.types.ts +++ b/packages/table-core/src/features/row-selection/RowSelection.types.ts @@ -1,6 +1,6 @@ import type { OnChangeFn, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Row } from '../../types/Row' export type RowSelectionState = Record @@ -60,28 +60,6 @@ export interface TableOptions_RowSelection< // ) => RowModel } -export interface TableOptions_RowSelection_Unavailable< - TFeatures extends TableFeatures, - TData extends RowData, -> { - /** - * @deprecated Import the `RowSelection` feature to use the row selection APIs. - */ - enableMultiRowSelection?: boolean | ((row: Row) => boolean) - /** - * @deprecated Import the `RowSelection` feature to use the row selection APIs. - */ - enableRowSelection?: boolean | ((row: Row) => boolean) - /** - * @deprecated Import the `RowSelection` feature to use the row selection APIs. - */ - enableSubRowSelection?: boolean | ((row: Row) => boolean) - /** - * @deprecated Import the `RowSelection` feature to use the row selection APIs. - */ - onRowSelectionChange?: OnChangeFn -} - export interface Row_RowSelection { /** * Returns whether or not the row can multi-select. diff --git a/packages/table-core/src/features/row-selection/RowSelection.utils.ts b/packages/table-core/src/features/row-selection/RowSelection.utils.ts index fefc66deb2..c0797dba2a 100644 --- a/packages/table-core/src/features/row-selection/RowSelection.utils.ts +++ b/packages/table-core/src/features/row-selection/RowSelection.utils.ts @@ -1,16 +1,11 @@ -import { table_getPreGroupedRowModel as RowSelectionUtils } from '../column-grouping/ColumnGrouping.utils' -import { table_getFilteredRowModel } from '../column-filtering/ColumnFiltering.utils' -import { table_getPaginatedRowModel } from '../row-pagination/RowPagination.utils' import { table_getRow } from '../../core/rows/Rows.utils' import { - table_getCoreRowModel, table_getInitialState, - table_getRowModel, table_getState, } from '../../core/table/Tables.utils' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' import type { RowSelectionState } from './RowSelection.types' @@ -68,7 +63,7 @@ export function table_toggleAllRowsSelected< const rowSelection = { ...old } - const preGroupedFlatRows = RowSelectionUtils(table).flatRows + const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows // We don't use `mutateRowIsSelected` here for performance reasons. // All of the rows are flat already, so it wouldn't be worth it @@ -106,7 +101,7 @@ export function table_toggleAllPageRowsSelected< const rowSelection: RowSelectionState = { ...old } - table_getRowModel(table).rows.forEach((row) => { + table.getRowModel().rows.forEach((row) => { mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table) }) @@ -123,7 +118,7 @@ export function table_getPreSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal): RowModel { - return table_getCoreRowModel(table) + return table.getCoreRowModel() } /** @@ -135,7 +130,7 @@ export function table_getSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const rowModel = table_getCoreRowModel(table) + const rowModel = table.getCoreRowModel() if (!Object.keys(table_getState(table).rowSelection ?? {}).length) { return { @@ -157,7 +152,7 @@ export function table_getFilteredSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const rowModel = table_getCoreRowModel(table) + const rowModel = table.getCoreRowModel() if (!Object.keys(table_getState(table).rowSelection ?? {}).length) { return { @@ -179,7 +174,7 @@ export function table_getGroupedSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const rowModel = table_getCoreRowModel(table) + const rowModel = table.getCoreRowModel() if (!Object.keys(table_getState(table).rowSelection ?? {}).length) { return { @@ -201,7 +196,7 @@ export function table_getIsAllRowsSelected< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const preGroupedFlatRows = table_getFilteredRowModel(table).flatRows + const preGroupedFlatRows = table.getFilteredRowModel().flatRows const rowSelection = table_getState(table).rowSelection ?? {} let isAllRowsSelected = Boolean( @@ -230,7 +225,7 @@ export function table_getIsAllPageRowsSelected< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const paginationFlatRows = table_getPaginatedRowModel(table).flatRows.filter( + const paginationFlatRows = table.getPaginatedRowModel().flatRows.filter( (row) => row_getCanSelect(row, table), ) const rowSelection = table_getState(table).rowSelection ?? {} @@ -261,7 +256,7 @@ export function table_getIsSomeRowsSelected< ).length return ( totalSelected > 0 && - totalSelected < table_getFilteredRowModel(table).flatRows.length + totalSelected < table.getFilteredRowModel().flatRows.length ) } @@ -274,7 +269,7 @@ export function table_getIsSomePageRowsSelected< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const paginationFlatRows = table_getPaginatedRowModel(table).flatRows + const paginationFlatRows = table.getPaginatedRowModel().flatRows return table_getIsAllPageRowsSelected(table) ? false : paginationFlatRows diff --git a/packages/table-core/src/features/row-sorting/RowSorting.ts b/packages/table-core/src/features/row-sorting/RowSorting.ts index a99b00c5f1..ded7ee0514 100644 --- a/packages/table-core/src/features/row-sorting/RowSorting.ts +++ b/packages/table-core/src/features/row-sorting/RowSorting.ts @@ -12,8 +12,6 @@ import { column_getSortingFn, column_getToggleSortingHandler, column_toggleSorting, - table_getPreSortedRowModel, - table_getSortedRowModel, table_resetSorting, table_setSorting, } from './RowSorting.utils' @@ -125,12 +123,6 @@ export const RowSorting: TableFeature = { { fn: (defaultState) => table_resetSorting(table, defaultState), }, - { - fn: () => table_getPreSortedRowModel(table), - }, - { - fn: () => table_getSortedRowModel(table), - }, ]) }, } diff --git a/packages/table-core/src/features/row-sorting/RowSorting.types.ts b/packages/table-core/src/features/row-sorting/RowSorting.types.ts index 163a964200..f63d3069f2 100644 --- a/packages/table-core/src/features/row-sorting/RowSorting.types.ts +++ b/packages/table-core/src/features/row-sorting/RowSorting.types.ts @@ -1,7 +1,8 @@ +import type { RowModel } from '../../core/row-models/RowModels.types' +import type { Table } from '../../types/Table' import type { BuiltInSortingFn } from '../../fns/sortingFns' import type { OnChangeFn, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' import type { Row } from '../../types/Row' export type SortDirection = 'asc' | 'desc' @@ -104,36 +105,6 @@ export interface ColumnDef_RowSorting< sortUndefined?: false | -1 | 1 | 'first' | 'last' } -export interface ColumnDef_RowSorting_Unavailable< - TFeatures extends TableFeatures, - TData extends RowData, -> { - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - enableMultiSort?: boolean - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - enableSorting?: boolean - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - invertSorting?: boolean - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - sortDescFirst?: boolean - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - sortingFn?: SortingFnOption - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - sortUndefined?: false | -1 | 1 | 'first' | 'last' -} - export interface Column_RowSorting< TFeatures extends TableFeatures, TData extends RowData, @@ -271,46 +242,25 @@ export interface TableOptions_RowSorting { sortDescFirst?: boolean } -export interface TableOptions_RowSorting_Unavailable { - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - enableMultiRemove?: boolean - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - enableMultiSort?: boolean - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - enableSorting?: boolean - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - enableSortingRemoval?: boolean - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - isMultiSortEvent?: (e: unknown) => boolean - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - manualSorting?: boolean - /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. - */ - maxMultiSortColCount?: number +export interface Table_RowSorting< + TFeatures extends TableFeatures, + TData extends RowData, +> { /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. + * Resets the **sorting** state to `initialState.sorting`, or `true` can be passed to force a default blank state reset to `[]`. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#resetsorting) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting) */ - onSortingChange?: OnChangeFn + resetSorting: (defaultState?: boolean) => void /** - * @deprecated Import the `RowSorting` feature to use the row sorting APIs. + * Sets or updates the `state.sorting` state. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#setsorting) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting) */ - sortDescFirst?: boolean + setSorting: (updater: Updater) => void } -export interface Table_RowSorting< +export interface Table_RowModels_Sorted< TFeatures extends TableFeatures, TData extends RowData, > { @@ -326,16 +276,25 @@ export interface Table_RowSorting< * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting) */ getSortedRowModel: () => RowModel +} + +export interface CreateRowModel_Sorted< + TFeatures extends TableFeatures, + TData extends RowData, +> { /** - * Resets the **sorting** state to `initialState.sorting`, or `true` can be passed to force a default blank state reset to `[]`. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#resetsorting) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting) - */ - resetSorting: (defaultState?: boolean) => void - /** - * Sets or updates the `state.sorting` state. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#setsorting) + * This function is used to retrieve the sorted row model. If using server-side sorting, this function is not required. To use client-side sorting, pass the exported `getSortedRowModel()` from your adapter to your table or implement your own. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortedrowmodel) * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting) */ - setSorting: (updater: Updater) => void + sortedRowModel?: ( + table: Table, + ) => () => RowModel +} + +export interface CachedRowModel_Sorted< + TFeatures extends TableFeatures, + TData extends RowData, +> { + sortedRowModel: () => RowModel } diff --git a/packages/table-core/src/features/row-sorting/RowSorting.utils.ts b/packages/table-core/src/features/row-sorting/RowSorting.utils.ts index 381f94295f..c0ffdc527b 100644 --- a/packages/table-core/src/features/row-sorting/RowSorting.utils.ts +++ b/packages/table-core/src/features/row-sorting/RowSorting.utils.ts @@ -1,15 +1,12 @@ import { reSplitAlphaNumeric, sortingFn_basic } from '../../fns/sortingFns' import { isFunction } from '../../utils' -import { table_getFilteredRowModel } from '../column-filtering/ColumnFiltering.utils' import { row_getValue } from '../../core/rows/Rows.utils' -import { table_getGroupedRowModel } from '../column-grouping/ColumnGrouping.utils' import { table_getInitialState, table_getState, } from '../../core/table/Tables.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' import type { Table_Internal } from '../../types/Table' import type { Column_Internal } from '../../types/Column' import type { SortDirection, SortingFn, SortingState } from './RowSorting.types' @@ -65,7 +62,7 @@ export function column_getAutoSortingFn< let sortingFn: SortingFn | undefined - const firstRows = table_getFilteredRowModel(table).flatRows.slice(10) + const firstRows = table.getFilteredRowModel().flatRows.slice(10) let isString = false @@ -106,7 +103,7 @@ export function column_getAutoSortDir< column: Column_Internal, table: Table_Internal, ) { - const firstRow = table_getFilteredRowModel(table).flatRows[0] + const firstRow = table.getFilteredRowModel().flatRows[0] const value = firstRow ? row_getValue(firstRow, table, column.id) : undefined @@ -435,32 +432,3 @@ export function column_getToggleSortingHandler< ) } } - -// Table Utils - -/** - * - * @param table - * @returns - */ -export function table_getPreSortedRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - return table_getGroupedRowModel(table) -} - -export function table_getSortedRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.Sorted) { - table._rowModels.Sorted = table.options._rowModels?.Sorted?.(table) - } - - if (table.options.manualSorting || !table._rowModels.Sorted) { - return table_getPreSortedRowModel(table) - } - - return table._rowModels.Sorted() -} diff --git a/packages/table-core/src/features/row-sorting/createSortedRowModel.ts b/packages/table-core/src/features/row-sorting/createSortedRowModel.ts index b06b9d302e..05984aa936 100644 --- a/packages/table-core/src/features/row-sorting/createSortedRowModel.ts +++ b/packages/table-core/src/features/row-sorting/createSortedRowModel.ts @@ -3,15 +3,11 @@ import { row_getValue } from '../../core/rows/Rows.utils' import { table_getColumn } from '../../core/columns/Columns.utils' import { table_getState } from '../../core/table/Tables.utils' import { table_autoResetPageIndex } from '../row-pagination/RowPagination.utils' -import { - column_getCanSort, - column_getSortingFn, - table_getPreSortedRowModel, -} from './RowSorting.utils' +import { column_getCanSort, column_getSortingFn } from './RowSorting.utils' import type { Column_Internal } from '../../types/Column' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../types/RowModel' +import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' import type { SortingFn } from './RowSorting.types' @@ -25,10 +21,10 @@ export function createSortedRowModel< return (table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), - fnName: 'table.createSortedRowModel', + fnName: 'table.getSortedRowModel', memoDeps: () => [ table_getState(table).sorting, - table_getPreSortedRowModel(table), + table.getPreSortedRowModel(), ], fn: () => _createSortedRowModel(table), onAfterUpdate: () => table_autoResetPageIndex(table), @@ -39,7 +35,7 @@ function _createSortedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal): RowModel { - const preSortedRowModel = table_getPreSortedRowModel(table) + const preSortedRowModel = table.getPreSortedRowModel() const sorting = table_getState(table).sorting if (!preSortedRowModel.rows.length || !sorting?.length) { @@ -50,7 +46,7 @@ function _createSortedRowModel< // Filter out sortings that correspond to non existing columns const availableSorting = sorting.filter((sort) => - column_getCanSort(table_getColumn(table, sort.id), table), + column_getCanSort(table_getColumn(table, sort.id)!, table), ) const columnInfoById: Record< @@ -125,7 +121,6 @@ function _createSortedRowModel< return sortInt } } - return rowA.index - rowB.index }) diff --git a/packages/table-core/src/index.ts b/packages/table-core/src/index.ts index d1cca6795c..7cd35cebac 100755 --- a/packages/table-core/src/index.ts +++ b/packages/table-core/src/index.ts @@ -8,6 +8,7 @@ export * from './types/ColumnDef' export * from './types/Header' export * from './types/HeaderGroup' export * from './types/Row' +export * from './types/RowModel' export * from './types/Table' export * from './types/TableFeatures' export * from './types/TableOptions' @@ -15,7 +16,7 @@ export * from './types/TableState' export * from './types/type-utils' /** - * Core + * coreRowModel */ export * from './core/coreFeatures' @@ -50,8 +51,13 @@ export * from './core/rows/Rows' export * from './core/rows/Rows.types' export * from './core/rows/Rows.utils' +// Row Models +export * from './core/row-models/RowModels' +export * from './core/row-models/RowModels.types' +export * from './core/row-models/RowModels.utils' +export * from './core/row-models/createCoreRowModel' + // Tables -export * from './core/table/createCoreRowModel' export * from './core/table/constructTable' export * from './core/table/Tables' export * from './core/table/Tables.types' diff --git a/packages/table-core/src/types/RowModel.ts b/packages/table-core/src/types/RowModel.ts index 0399d446fb..3cb594c345 100644 --- a/packages/table-core/src/types/RowModel.ts +++ b/packages/table-core/src/types/RowModel.ts @@ -1,107 +1,105 @@ -import type { RowData } from './type-utils' +import type { + CachedRowModel_Faceted, + CreateRowModel_Faceted, +} from '../features/column-faceting/ColumnFaceting.types' +import type { + CachedRowModel_Grouped, + CreateRowModel_Grouped, +} from '../features/column-grouping/ColumnGrouping.types' +import type { + CachedRowModel_Filtered, + CreateRowModel_Filtered, +} from '../features/column-filtering/ColumnFiltering.types' +import type { + CachedRowModel_Core, + CreateRowModel_Core, + RowModel, +} from '../core/row-models/RowModels.types' +import type { + CachedRowModel_Expanded, + CreateRowModel_Expanded, +} from '../features/row-expanding/RowExpanding.types' +import type { + CachedRowModel_Paginated, + CreateRowModel_Paginated, +} from '../features/row-pagination/RowPagination.types' +import type { + CachedRowModel_Sorted, + CreateRowModel_Sorted, +} from '../features/row-sorting/RowSorting.types' +import type { RowData, UnionToIntersection } from './type-utils' import type { TableFeatures } from './TableFeatures' -import type { Row } from './Row' -import type { Table } from './Table' -export interface RowModel< +export type CreateRowModels< TFeatures extends TableFeatures, TData extends RowData, -> { - rows: Array> - flatRows: Array> - rowsById: Record> -} +> = CreateRowModel_Core & + UnionToIntersection< + | ('ColumnFaceting' extends keyof TFeatures + ? CreateRowModel_Faceted + : never) + | ('ColumnFiltering' extends keyof TFeatures + ? CreateRowModel_Filtered + : never) + | ('RowExpanding' extends keyof TFeatures + ? CreateRowModel_Expanded + : never) + | ('ColumnGrouping' extends keyof TFeatures + ? CreateRowModel_Grouped + : never) + | ('RowPagination' extends keyof TFeatures + ? CreateRowModel_Paginated + : never) + | ('RowSorting' extends keyof TFeatures + ? CreateRowModel_Sorted + : never) + > -export interface RowModelOptions< +export type CreateRowModels_All< TFeatures extends TableFeatures, TData extends RowData, -> { - /** - * This required option is a factory for a function that computes and returns the core row model for the table. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getcorerowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables) - */ - Core?: (table: Table) => () => RowModel - /** - * This function is responsible for returning the expanded row model. If this function is not provided, the table will not expand rows. You can use the default exported `getExpandedRowModel` function to get the expanded row model or implement your own. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getexpandedrowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding) - */ - Expanded?: ( - table: Table, - ) => () => RowModel - /** - * If provided, this function is called **once** per table and should return a **new function** which will calculate and return the row model for the table when it's filtered. - * - For server-side filtering, this function is unnecessary and can be ignored since the server should already return the filtered row model. - * - For client-side filtering, this function is required. A default implementation is provided via any table adapter's `{ getFilteredRowModel }` export. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfilteredrowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) - */ - Filtered?: ( - table: Table, - ) => () => RowModel - /** - * Returns the row model after grouping has taken place, but no further. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupedrowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping) - */ - Grouped?: (table: Table) => () => RowModel - /** - * Returns the row model after pagination has taken place, but no further. - * - * Pagination columns are automatically reordered by default to the start of the columns list. If you would rather remove them or leave them as-is, set the appropriate mode here. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getPaginatedRowModel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination) - */ - Paginated?: ( - table: Table, - ) => () => RowModel - /** - * This function is used to retrieve the sorted row model. If using server-side sorting, this function is not required. To use client-side sorting, pass the exported `getSortedRowModel()` from your adapter to your table or implement your own. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortedrowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting) - */ - Sorted?: (table: Table) => () => RowModel - /** - * This function is used to retrieve the faceted min/max values. If using server-side faceting, this function is not required. To use client-side faceting, pass the exported `getFacetedMinMaxValues()` from your adapter to your table or implement your own. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-faceting#getfacetedminmaxvalues) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting) - */ - FacetedMinMax?: ( - table: Table, - columnId: string, - ) => () => [number, number] | undefined - /** - * This function is used to retrieve the faceted row model. If using server-side faceting, this function is not required. To use client-side faceting, pass the exported `getFacetedRowModel()` from your adapter to your table or implement your own. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-faceting#getfacetedrowmodel) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting) - */ - Faceted?: ( - table: Table, - columnId: string, - ) => () => RowModel - /** - * This function is used to retrieve the faceted unique values. If using server-side faceting, this function is not required. To use client-side faceting, pass the exported `getFacetedUniqueValues()` from your adapter to your table or implement your own. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-faceting#getfaceteduniquevalues) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting) - */ - FacetedUnique?: ( - table: Table, - columnId: string, - ) => () => Map -} +> = CreateRowModel_Core & + CreateRowModel_Expanded & + CreateRowModel_Faceted & + CreateRowModel_Filtered & + CreateRowModel_Grouped & + CreateRowModel_Paginated & + CreateRowModel_Sorted -export interface CachedRowModels< +export type CachedRowModels< TFeatures extends TableFeatures, TData extends RowData, -> { - Core?: () => RowModel - Expanded?: () => RowModel - Filtered?: () => RowModel - Grouped?: () => RowModel - Paginated?: () => RowModel - Sorted?: () => RowModel - FacetedMinMax?: (columnId: string) => [number, number] - Faceted?: (columnId: string) => RowModel - FacetedUnique?: (columnId: string) => Map -} +> = { + core?: () => RowModel +} & UnionToIntersection< + | ('ColumnFaceting' extends keyof TFeatures + ? CachedRowModel_Faceted + : never) + | ('ColumnFiltering' extends keyof TFeatures + ? CachedRowModel_Filtered + : never) + | ('RowExpanding' extends keyof TFeatures + ? CachedRowModel_Expanded + : never) + | ('ColumnGrouping' extends keyof TFeatures + ? CachedRowModel_Grouped + : never) + | ('RowPagination' extends keyof TFeatures + ? CachedRowModel_Paginated + : never) + | ('RowSorting' extends keyof TFeatures + ? CachedRowModel_Sorted + : never) +> + +export type CachedRowModel_All< + TFeatures extends TableFeatures, + TData extends RowData, +> = Partial< + CachedRowModel_Core & + CachedRowModel_Expanded & + CachedRowModel_Filtered & + CachedRowModel_Grouped & + CachedRowModel_Paginated & + CachedRowModel_Sorted +> diff --git a/packages/table-core/src/types/Table.ts b/packages/table-core/src/types/Table.ts index 85c8620ad3..4fcea185c4 100644 --- a/packages/table-core/src/types/Table.ts +++ b/packages/table-core/src/types/Table.ts @@ -1,3 +1,5 @@ +import type { Table_RowModels } from '../core/row-models/RowModels.types' +import type { CachedRowModel_All, CreateRowModels_All } from './RowModel' import type { ProcessingFns_All } from './ProcessingFns' import type { TableState_All } from './TableState' import type { RowData, UnionToIntersection } from './type-utils' @@ -26,13 +28,14 @@ import type { TableOptions_All } from './TableOptions' * The core table object that only includes the core table functionality such as column, header, row, and table APIS. * No features are included. */ -export interface Table_Core< +export type Table_Core< TFeatures extends TableFeatures, TData extends RowData, -> extends Table_Table, - Table_Columns, - Table_Rows, - Table_Headers {} +> = Table_Table & + Table_Columns & + Table_Rows & + Table_RowModels & + Table_Headers /** * The table object that includes both the core table functionality and the features that are enabled via the `_features` table option. @@ -87,6 +90,9 @@ export type Table_Internal< TData extends RowData, > = Table & { _processingFns: ProcessingFns_All + _rowModels: CachedRowModel_All getState: () => TableState_All - options: TableOptions_All + options: TableOptions_All & { + _rowModels?: CreateRowModels_All + } } diff --git a/packages/table-core/tests/RowPinning.test.ts b/packages/table-core/tests/RowPinning.test.ts index 85b810e147..937462788f 100644 --- a/packages/table-core/tests/RowPinning.test.ts +++ b/packages/table-core/tests/RowPinning.test.ts @@ -36,7 +36,7 @@ describe('RowPinning', () => { const table = constructTable({ _features: { RowPinning, RowPagination }, _rowModels: { - Paginated: createPaginatedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, enableRowPinning: true, keepPinnedRows: true, @@ -69,7 +69,7 @@ describe('RowPinning', () => { const table = constructTable({ _features: { RowPinning, RowPagination }, _rowModels: { - Paginated: createPaginatedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, enableRowPinning: true, keepPinnedRows: true, @@ -102,7 +102,7 @@ describe('RowPinning', () => { const table = constructTable({ _features: { RowPinning, RowPagination }, _rowModels: { - Paginated: createPaginatedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, enableRowPinning: true, keepPinnedRows: false, @@ -135,7 +135,7 @@ describe('RowPinning', () => { const table = constructTable({ _features: { RowPinning, RowPagination }, _rowModels: { - Paginated: createPaginatedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, enableRowPinning: true, keepPinnedRows: false, @@ -167,7 +167,7 @@ describe('RowPinning', () => { const table = constructTable({ _features: { RowPinning, RowPagination }, _rowModels: { - Paginated: createPaginatedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, enableRowPinning: true, keepPinnedRows: true, @@ -200,7 +200,7 @@ describe('RowPinning', () => { const table = constructTable({ _features: { RowPinning, RowPagination }, _rowModels: { - Paginated: createPaginatedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, enableRowPinning: true, keepPinnedRows: true, @@ -235,7 +235,7 @@ describe('RowPinning', () => { const table = constructTable({ _features: { RowPinning, RowPagination }, _rowModels: { - Paginated: createPaginatedRowModel(), + paginatedRowModel: createPaginatedRowModel(), }, enableRowPinning: true, keepPinnedRows: true, diff --git a/packages/table-core/tests/getGroupedRowModel.test.ts b/packages/table-core/tests/getGroupedRowModel.test.ts index 8142c972d8..0d5166d281 100644 --- a/packages/table-core/tests/getGroupedRowModel.test.ts +++ b/packages/table-core/tests/getGroupedRowModel.test.ts @@ -39,7 +39,7 @@ describe('#getGroupedRowModel', () => { const table = constructTable({ _features: { ColumnGrouping }, _rowModels: { - Grouped: createGroupedRowModel(), + groupedRowModel: createGroupedRowModel(), }, onStateChange() {}, renderFallbackValue: '',