Skip to content

Commit

Permalink
work on visibility stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Feb 28, 2024
1 parent c31ae22 commit 922e45e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
Expand Up @@ -359,6 +359,13 @@ export const tableInstanceAPIs: TableInstanceAPI[] = [
link: '',
linkText: '',
},
{
tableInstanceAPI: 'getRowCount',
type: '',
description: '',
link: '',
linkText: '',
},
{
tableInstanceAPI: 'getPageOptions',
type: '',
Expand Down Expand Up @@ -850,7 +857,14 @@ export const tableInstanceAPIs: TableInstanceAPI[] = [
linkText: '',
},
{
tableInstanceAPI: 'setPageCount',
tableInstanceAPI: 'lastPage',
type: '',
description: '',
link: '',
linkText: '',
},
{
tableInstanceAPI: 'firstPage',
type: '',
description: '',
link: '',
Expand Down
Expand Up @@ -47,7 +47,9 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({

const handleToggleAllColumns = (value?: boolean) => {
getAllLeafColumns()
.filter((col) => col.columnDef.enableHiding !== false)
.filter(
(col) => col.columnDef.enableHiding !== false && !col.getIsPinned(),
)
.forEach((col) => col.toggleVisibility(value));
};

Expand Down
Expand Up @@ -66,13 +66,8 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
column?.columns?.forEach?.((childColumn: MRT_Column<TData>) => {
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)
}
}
};

Expand Down
Expand Up @@ -16,10 +16,7 @@ export const useMRT_ColumnVirtualizer = <
table: MRT_TableInstance<TData>,
): MRT_ColumnVirtualizer | undefined => {
const {
getLeftLeafColumns,
getRightLeafColumns,
getState,
getVisibleLeafColumns,
options: {
columnVirtualizerInstanceRef,
columnVirtualizerOptions,
Expand All @@ -28,7 +25,7 @@ export const useMRT_ColumnVirtualizer = <
},
refs: { tableContainerRef },
} = table;
const { columnPinning, draggingColumn } = getState();
const { columnPinning, columnVisibility, draggingColumn } = getState();

if (!enableColumnVirtualization) return undefined;

Expand All @@ -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;
Expand Down

0 comments on commit 922e45e

Please sign in to comment.