Skip to content

Commit 1b0d5f6

Browse files
committed
add types for methods
1 parent 76af13d commit 1b0d5f6

File tree

2 files changed

+91
-13
lines changed

2 files changed

+91
-13
lines changed

src/BaseTable.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ class BaseTable extends React.PureComponent {
208208

209209
/**
210210
* Reset cached offsets for positioning after a specific rowIndex, should be used only in dynamic mode(estimatedRowHeight is provided)
211+
*
212+
* @param {number} rowIndex
213+
* @param {boolean} shouldForceUpdate
211214
*/
212215
resetAfterRowIndex(rowIndex = 0, shouldForceUpdate = true) {
213216
if (!this.props.estimatedRowHeight) return;
@@ -279,7 +282,7 @@ class BaseTable extends React.PureComponent {
279282
* - `center` - Center align the row within the table.
280283
* - `end` - Align the row to the bottom side of the table.
281284
* - `start` - Align the row to the top side of the table.
282-
285+
*
283286
* @param {number} rowIndex
284287
* @param {string} align
285288
*/

types/index.d.ts

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ declare module 'react-base-table' {
119119
columnIndex: number;
120120
rowData: T;
121121
rowIndex: number;
122-
container: any;
122+
container: BaseTable<T>;
123123
isScrolling?: boolean;
124124
}
125125
>;
@@ -134,7 +134,7 @@ declare module 'react-base-table' {
134134
column: ColumnShape<T>;
135135
columnIndex: number;
136136
headerIndex: number;
137-
container: any;
137+
container: BaseTable<T>;
138138
}
139139
>;
140140
[key: string]: any;
@@ -402,12 +402,12 @@ declare module 'react-base-table' {
402402
* A callback function when resizing the column width
403403
* The handler is of the shape of `({ column, width }) => *`
404404
*/
405-
onColumnResize?: (args: { column: ColumnShape; width: number }) => void;
405+
onColumnResize?: (args: { column: ColumnShape<T>; width: number }) => void;
406406
/**
407407
* A callback function when resizing the column width ends
408408
* The handler is of the shape of `({ column, width }) => *`
409409
*/
410-
onColumnResizeEnd?: (args: { column: ColumnShape; width: number }) => void;
410+
onColumnResizeEnd?: (args: { column: ColumnShape<T>; width: number }) => void;
411411
/**
412412
* Adds an additional isScrolling parameter to the row renderer.
413413
* This parameter can be used to show a placeholder row while scrolling.
@@ -482,25 +482,25 @@ declare module 'react-base-table' {
482482
[key: string]: any;
483483
}
484484

485-
export interface TableComponents {
485+
export interface TableComponents<T = any> {
486486
TableCell?: React.ElementType<{
487487
className: string;
488488
isScrolling?: boolean;
489489
cellData: any;
490-
columns: ColumnShape[];
491-
column: ColumnShape;
490+
columns: ColumnShape<T>[];
491+
column: ColumnShape<T>;
492492
columnIndex: number;
493-
rowData: any;
493+
rowData: T;
494494
rowIndex: number;
495-
container: any;
495+
container: BaseTable<T>;
496496
}>;
497497
TableHeaderCell?: React.ElementType<{
498498
className: string;
499-
columns: ColumnShape[];
500-
column: ColumnShape;
499+
columns: ColumnShape<T>[];
500+
column: ColumnShape<T>;
501501
columnIndex: number;
502502
headerIndex: number;
503-
container: any;
503+
container: BaseTable<T>;
504504
}>;
505505
ExpandIcon?: React.ElementType<{
506506
depth: number;
@@ -518,6 +518,81 @@ declare module 'react-base-table' {
518518
export default class BaseTable<T = unknown> extends React.Component<BaseTableProps<T>, any> {
519519
static readonly Column: typeof Column;
520520
static readonly PlaceholderKey = '__placeholder__';
521+
522+
/**
523+
* Get the DOM node of the table
524+
*/
525+
getDOMNode(): HTMLDivElement | null;
526+
/**
527+
* Get the column manager
528+
*/
529+
getColumnManager(): any;
530+
/**
531+
* Get internal `expandedRowKeys` state
532+
*/
533+
getExpandedRowKeys(): RowKey[];
534+
/**
535+
* Get the expanded state, fallback to normal state if not expandable.
536+
*/
537+
getExpandedState(): {
538+
expandedData: T[];
539+
expandedRowKeys: RowKey[];
540+
expandedDepthMap: { [key: RowKey]: number };
541+
};
542+
/**
543+
* Get the total height of all rows, including expanded rows.
544+
*/
545+
getTotalRowsHeight(): number;
546+
/**
547+
* Get the total width of all columns.
548+
*/
549+
getTotalColumnsWidth(): number;
550+
/**
551+
* Forcefully re-render the inner Grid component.
552+
*
553+
* Calling `forceUpdate` on `Table` may not re-render the inner Grid since it uses `shallowCompare` as a performance optimization.
554+
* Use this method if you want to manually trigger a re-render.
555+
* This may be appropriate if the underlying row data has changed but the row sizes themselves have not.
556+
*/
557+
forceUpdateTable(): void;
558+
/**
559+
* Reset cached offsets for positioning after a specific rowIndex, should be used only in dynamic mode(estimatedRowHeight is provided)
560+
*/
561+
resetAfterRowIndex(rowIndex?: number, shouldForceUpdate?: boolean): void;
562+
/**
563+
* Reset row height cache, useful if `data` changed entirely, should be used only in dynamic mode(estimatedRowHeight is provided)
564+
*/
565+
resetRowHeightCache(): void;
566+
/**
567+
* Scroll to the specified offset.
568+
* Useful for animating position changes.
569+
*/
570+
scrollToPosition(offset: { scrollLeft: number; scrollTop: number }): void;
571+
/**
572+
* Scroll to the specified offset vertically.
573+
*/
574+
scrollToTop(scrollTop: number): void;
575+
/**
576+
* Scroll to the specified offset horizontally.
577+
*/
578+
scrollToLeft(scrollLeft: number): void;
579+
/**
580+
* Scroll to the specified row.
581+
* By default, the table will scroll as little as possible to ensure the row is visible.
582+
* You can control the alignment of the row though by specifying an align property. Acceptable values are:
583+
*
584+
* - `auto` (default) - Scroll as little as possible to ensure the row is visible.
585+
* - `smart` - Same as `auto` if it is less than one viewport away, or it's the same as`center`.
586+
* - `center` - Center align the row within the table.
587+
* - `end` - Align the row to the bottom side of the table.
588+
* - `start` - Align the row to the top side of the table.
589+
*/
590+
scrollToRow(rowIndex?: number, align?: 'auto' | 'smart' | 'center' | 'end' | 'start'): void;
591+
/**
592+
* Set `expandedRowKeys` manually.
593+
* This method is available only if `expandedRowKeys` is uncontrolled.
594+
*/
595+
setExpandedRowKeys(expandedRowKeys: RowKey[]): void;
521596
}
522597

523598
export interface AutoResizerProps {

0 commit comments

Comments
 (0)