From 922e45e3c589b3e46051632fe93960f14e2bf996 Mon Sep 17 00:00:00 2001 From: Kevin Van Cott Date: Wed, 28 Feb 2024 09:12:23 -0600 Subject: [PATCH] work on visibility stuff --- .../components/prop-tables/tableInstanceAPIs.ts | 16 +++++++++++++++- .../components/menus/MRT_ShowHideColumnsMenu.tsx | 4 +++- .../menus/MRT_ShowHideColumnsMenuItems.tsx | 5 ----- .../src/hooks/useMRT_ColumnVirtualizer.ts | 14 ++++++-------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/apps/material-react-table-docs/components/prop-tables/tableInstanceAPIs.ts b/apps/material-react-table-docs/components/prop-tables/tableInstanceAPIs.ts index 00823142f..257c7fde7 100644 --- a/apps/material-react-table-docs/components/prop-tables/tableInstanceAPIs.ts +++ b/apps/material-react-table-docs/components/prop-tables/tableInstanceAPIs.ts @@ -359,6 +359,13 @@ export const tableInstanceAPIs: TableInstanceAPI[] = [ link: '', linkText: '', }, + { + tableInstanceAPI: 'getRowCount', + type: '', + description: '', + link: '', + linkText: '', + }, { tableInstanceAPI: 'getPageOptions', type: '', @@ -850,7 +857,14 @@ export const tableInstanceAPIs: TableInstanceAPI[] = [ linkText: '', }, { - tableInstanceAPI: 'setPageCount', + tableInstanceAPI: 'lastPage', + type: '', + description: '', + link: '', + linkText: '', + }, + { + tableInstanceAPI: 'firstPage', type: '', description: '', link: '', diff --git a/packages/material-react-table/src/components/menus/MRT_ShowHideColumnsMenu.tsx b/packages/material-react-table/src/components/menus/MRT_ShowHideColumnsMenu.tsx index c839a5111..a680c69c9 100644 --- a/packages/material-react-table/src/components/menus/MRT_ShowHideColumnsMenu.tsx +++ b/packages/material-react-table/src/components/menus/MRT_ShowHideColumnsMenu.tsx @@ -47,7 +47,9 @@ export const MRT_ShowHideColumnsMenu = ({ const handleToggleAllColumns = (value?: boolean) => { getAllLeafColumns() - .filter((col) => col.columnDef.enableHiding !== false) + .filter( + (col) => col.columnDef.enableHiding !== false && !col.getIsPinned(), + ) .forEach((col) => col.toggleVisibility(value)); }; diff --git a/packages/material-react-table/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx b/packages/material-react-table/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx index 9a9e4b587..f376256b5 100644 --- a/packages/material-react-table/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +++ b/packages/material-react-table/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx @@ -66,13 +66,8 @@ export const MRT_ShowHideColumnsMenuItems = ({ column?.columns?.forEach?.((childColumn: MRT_Column) => { childColumn.toggleVisibility(!switchChecked); }); - column.toggleVisibility(!switchChecked); } else { column.toggleVisibility(); - if(column?.parent) { - const isOneVisible = column.parent.getLeafColumns().some((col) => col === column ? !col.getIsVisible() : col.getIsVisible()); - column.parent.toggleVisibility(isOneVisible) - } } }; diff --git a/packages/material-react-table/src/hooks/useMRT_ColumnVirtualizer.ts b/packages/material-react-table/src/hooks/useMRT_ColumnVirtualizer.ts index 13be391a8..07efa1ff1 100644 --- a/packages/material-react-table/src/hooks/useMRT_ColumnVirtualizer.ts +++ b/packages/material-react-table/src/hooks/useMRT_ColumnVirtualizer.ts @@ -16,10 +16,7 @@ export const useMRT_ColumnVirtualizer = < table: MRT_TableInstance, ): MRT_ColumnVirtualizer | undefined => { const { - getLeftLeafColumns, - getRightLeafColumns, getState, - getVisibleLeafColumns, options: { columnVirtualizerInstanceRef, columnVirtualizerOptions, @@ -28,7 +25,7 @@ export const useMRT_ColumnVirtualizer = < }, refs: { tableContainerRef }, } = table; - const { columnPinning, draggingColumn } = getState(); + const { columnPinning, columnVisibility, draggingColumn } = getState(); if (!enableColumnVirtualization) return undefined; @@ -39,21 +36,22 @@ export const useMRT_ColumnVirtualizer = < }, ); - const visibleColumns = getVisibleLeafColumns(); + const visibleColumns = table.getVisibleLeafColumns(); const [leftPinnedIndexes, rightPinnedIndexes] = useMemo( () => enableColumnPinning ? [ - getLeftLeafColumns().map((c) => c.getPinnedIndex()), - getRightLeafColumns() + table.getLeftVisibleLeafColumns().map((c) => c.getPinnedIndex()), + table + .getRightVisibleLeafColumns() .map( (column) => visibleColumns.length - column.getPinnedIndex() - 1, ) .sort((a, b) => a - b), ] : [[], []], - [columnPinning, enableColumnPinning], + [columnPinning, columnVisibility, enableColumnPinning], ); const numPinnedLeft = leftPinnedIndexes.length;