Custom column "collapse" property in typescript #2421
Replies: 4 comments 3 replies
-
The custom properties needs to be explicitly added to react-table type definitions.
export interface ColumnInterface<D extends object = {}>
extends UseFiltersColumnOptions<D>,
UseGroupByColumnOptions<D>,
UseSortByColumnOptions<D> {
hidden?: boolean;
className?: string;
align?: "left" | "center" | "right";
} That should do it. Try and let me know if that works for you. |
Beta Was this translation helpful? Give feedback.
-
To be able to access the custom props in JSX during table rendering, you should also add the custom props to interface CustomColumn {
sticky?: boolean;
}
declare module 'react-table' {
export interface ColumnInterface<
D extends Record<string, unknown> = Record<string, unknown>
> extends UseFiltersColumnOptions<D>,
UseGlobalFiltersColumnOptions<D>,
UseGroupByColumnOptions<D>,
UseResizeColumnsColumnOptions<D>,
UseSortByColumnOptions<D>,
CustomColumn {}
export interface ColumnInstance<
D extends Record<string, unknown> = Record<string, unknown>
> extends UseFiltersColumnProps<D>,
UseGroupByColumnProps<D>,
UseResizeColumnsColumnProps<D>,
UseSortByColumnProps<D>,
CustomColumn {}
} You can read official docs here: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-table#configuration-using-declaration-merging |
Beta Was this translation helpful? Give feedback.
-
i thought that v8 was written in typescript, why do i get |
Beta Was this translation helpful? Give feedback.
-
Is there a way to do this in v8 without using the meta properties so consuming the table I get types? I have this as my type, but it does not give my types via intellisense, when trying to add export type TableColumn<
D extends object = {
headerAlignment?: 'left' | 'right' | 'center';
cellAligment?: 'left' | 'right' | 'center';
}
> = ColumnDef<D>; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys, second day working with react-table (v7). I would like to add a "collapse" property to my column definition, something like:
The example below works fine, but I cannot get the same working in typescript. Any suggestions for adding custom props in typescript? Probably missing something obvious, apologies in advance!
#2421
Beta Was this translation helpful? Give feedback.
All reactions