Skip to content

How to create a table component using material-react-table #560

Discussion options

You must be logged in to vote

You can define a re-usable MRT component that can take any data, but you will probably want to use a TypeScript generic.

//extend MaterialReactTableProps so you don't have to type out 200 props yourself
interface Props<TData extends Record<string, any> = {}> extends MaterialReactTableProps<TData> {
  columns: MRT_ColumnDef<TData>[];
  data: TData[];
 //etc.
}

export const YourCustomTableComponent = <TData extends Record<string, any> = {}>({
  columns,
  data,
  ...rest
}: Props<TData>) => {
  //code... maybe custom columns...
  return (
    <MaterialReactTable
      columns={columns}
      data={data}
      //your prop customizations
      {...rest}
    />
  );
}

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@emanuella92gomesr
Comment options

@KevinVandy
Comment options

@emanuella92gomesr
Comment options

@ronnyhaase
Comment options

@ronnyhaase
Comment options

Answer selected by emanuella92gomesr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants