Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(data-grid): Expose table-instance via ref #3670

Merged
merged 1 commit into from
Nov 4, 2024
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
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