Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ yarn-error.log
lerna-debug.log
/temp
*.tsbuildinfo
.DS_Store

.pnp.*
.yarn/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@ export const F2CellEdit: Story = {

// Wide columns force horizontal overflow so the frozen-start columns visibly stay pinned while scrolling.
const stickyColumns: AnalyticalTableColumnDefinition[] = [
{ Header: 'Name', accessor: 'name', sticky: 'start', width: 200 },
{ Header: 'Age', accessor: 'age', width: 300 },
{ Header: 'Friend Name', accessor: 'friend.name', width: 300 },
{ Header: 'Friend Age', accessor: 'friend.age', width: 300 },
{ Header: 'Name', accessor: 'name', sticky: 'start', width: 300 },
{ Header: 'Age', accessor: 'age', width: 500 },
{ Header: 'Friend Name', accessor: 'friend.name', width: 1000 },
{ Header: 'Friend Age', accessor: 'friend.age', width: 500 },
];

export const StickyColumns: Story = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,27 @@ The hook accepts an options object with two optional callbacks:
<Canvas sourceState="none" of={ComponentStories.StickyColumns} />

```jsx
const TableComponent = (props) => {
const handleStickyColumnsChange = useCallback((detail) => {
console.log(detail.column, detail.sticky, detail.stickyColumns);
}, []);
const columns = [
{ Header: 'Name', accessor: 'name', sticky: 'start', width: 300 }, // seeds the initial frozen state
{ Header: 'Age', accessor: 'age', width: 500 },
{ Header: 'Friend Name', accessor: 'friend.name', width: 1000 },
{ Header: 'Friend Age', accessor: 'friend.age', width: 500 },
];

const TableComponent = (props) => {
// Fired only when a column is frozen/unfrozen via the header popover, not on programmatic toggling.
const tableHooks = useMemo(
() => [useStickyColumns({ onStickyColumnsChange: handleStickyColumnsChange })],
[handleStickyColumnsChange],
);

const columns = useMemo(
() => [
{ Header: 'Name', accessor: 'name', sticky: 'start' }, // seeds the initial frozen state
{ Header: 'Age', accessor: 'age' },
{ Header: 'Friend Name', accessor: 'friend.name', disableSticky: true }, // cannot be frozen via the popover
useStickyColumns({
onStickyColumnsChange: (detail) => {
console.log(detail.column, detail.sticky, detail.stickyColumns);
},
}),
],
[],
);

return <AnalyticalTable data={props.data} columns={columns} sortable tableHooks={tableHooks} />;
return <AnalyticalTable data={props.data} columns={columns} sortable filterable groupable tableHooks={tableHooks} />;
};
```

Expand Down
6 changes: 4 additions & 2 deletions packages/main/src/components/AnalyticalTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,8 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp

const totalSize = columnVirtualizer.getTotalSize();
const showVerticalEndBorder = tableState.tableClientWidth > totalSize;
const showVerticalScrollbar =
!nativeScrollbar && !hasStickyColumns && (!!additionalEmptyRowsCount || tableState.isScrollable);
// Sticky mode uses the native vertical scrollbar; reserve its height for the horizontal scrollbar.
const horizontalScrollbarReserved =
hasStickyColumns && scrollbarWidth > 0 && tableState.tableClientWidth > 0 && tableState.tableClientWidth < totalSize
Expand Down Expand Up @@ -923,7 +925,7 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
isRtl={isRtl}
columnVirtualizer={columnVirtualizer}
uniqueId={uniqueId}
showVerticalEndBorder={showVerticalEndBorder}
showVerticalEndBorder={showVerticalEndBorder && !showVerticalScrollbar}
classNames={classNames}
stickyStartIndices={stickyStartIndices}
/>
Expand Down Expand Up @@ -1011,7 +1013,7 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
style={{ insetBlockEnd: horizontalScrollbarReserved }}
/>
)}
{!nativeScrollbar && !hasStickyColumns && (additionalEmptyRowsCount || tableState.isScrollable) && (
{showVerticalScrollbar && (
<VerticalScrollbar
tableBodyHeight={tableBodyHeight}
internalRowHeight={internalHeaderRowHeight}
Expand Down
Loading