Skip to content

Commit

Permalink
feat(data-grid): Expose table-instance via ref (#3670)
Browse files Browse the repository at this point in the history
Resolves #3586
  • Loading branch information
yusijs authored Nov 4, 2024
1 parent c461e8f commit 6869b88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/eds-data-grid-react/src/EdsDataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function EdsDataGrid<T>({
height,
getRowId,
rowVirtualizerInstanceRef,
tableInstanceRef,
columnSizing,
onColumnResize,
expansionState,
Expand Down Expand Up @@ -334,6 +335,9 @@ export function EdsDataGrid<T>({
}, [pageSize])

const table = useReactTable(options)
if (tableInstanceRef) {
tableInstanceRef.current = table
}

let tableWrapperStyle: CSSProperties = {}

Expand Down
6 changes: 4 additions & 2 deletions packages/eds-data-grid-react/src/EdsDataGridProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Row,
RowSelectionState,
SortingState,
Table,
TableOptions,
} from '@tanstack/react-table'
import { Virtualizer } from '@tanstack/react-virtual'
Expand Down Expand Up @@ -307,11 +308,12 @@ type ColumnProps = {
onColumnResize?: (e: ColumnSizingState) => void
}

type RefProps = {
type RefProps<T> = {
rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<
HTMLDivElement,
Element
> | null>
tableInstanceRef?: MutableRefObject<Table<T> | null>
}

type ExpansionProps<T> = {
Expand All @@ -329,7 +331,7 @@ export type EdsDataGridProps<T> = BaseProps<T> &
PagingProps &
ColumnProps &
VirtualProps &
RefProps &
RefProps<T> &
ExpansionProps<T> & {
/**
* Which columns are visible. If not set, all columns are visible. undefined means that the column is visible.
Expand Down

0 comments on commit 6869b88

Please sign in to comment.