Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Adding a custom class to mantineTableHeadRowProps is not working #254

Closed
williamneves opened this issue Jan 24, 2024 · 0 comments
Closed
Labels
V2 Issue with MRT V2

Comments

@williamneves
Copy link
Contributor

williamneves commented Jan 24, 2024

mantine-react-table version

v2.0.0@alpha-10

react & react-dom versions

v^18.2.0

Describe the bug and the steps to reproduce it

I'm trying to modify the backgroundColor from the header, but inserting a new custom class to ``mantineTableHeadRowProps` on tableProps is not working:

mantineTableHeadRowProps: row =>({
      className: 'my-custom-class',
    }),

this is not working, the class is not added to the component.

Minimal, Reproducible Example - (Optional, but Recommended)

import 'mantine-react-table/styles.css'; //make sure MRT styles were imported in your app root (once)
import { useMemo } from 'react';
import {
  MantineReactTable,
  useMantineReactTable,
  type MRT_ColumnDef,
} from 'mantine-react-table';

type Person = {
  name: {
    firstName: string;
    lastName: string;
  };
  address: string;
  city: string;
  state: string;
};

//nested data is ok, see accessorKeys in ColumnDef below
const data: Person[] = [
  {
    name: {
      firstName: 'Zachary',
      lastName: 'Davis',
    },
    address: '261 Battle Ford',
    city: 'Columbus',
    state: 'Ohio',
  },
  {
    name: {
      firstName: 'Robert',
      lastName: 'Smith',
    },
    address: '566 Brakus Inlet',
    city: 'Westerville',
    state: 'West Virginia',
  },
  {
    name: {
      firstName: 'Kevin',
      lastName: 'Yan',
    },
    address: '7777 Kuhic Knoll',
    city: 'South Linda',
    state: 'West Virginia',
  },
  {
    name: {
      firstName: 'John',
      lastName: 'Upton',
    },
    address: '722 Emie Stream',
    city: 'Huntington',
    state: 'Washington',
  },
  {
    name: {
      firstName: 'Nathan',
      lastName: 'Harris',
    },
    address: '1 Kuhic Knoll',
    city: 'Ohiowa',
    state: 'Nebraska',
  },
];

const Example = () => {
  //should be memoized or stable
  const columns = useMemo<MRT_ColumnDef<Person>[]>(
    () => [
      {
        accessorKey: 'name.firstName', //access nested data with dot notation
        header: 'First Name',
      },
      {
        accessorKey: 'name.lastName',
        header: 'Last Name',
      },
      {
        accessorKey: 'address', //normal accessorKey
        header: 'Address',
      },
      {
        accessorKey: 'city',
        header: 'City',
      },
      {
        accessorKey: 'state',
        header: 'State',
      },
    ],
    [],
  );

  const table = useMantineReactTable({
    columns,
    data, //must be memoized or stable (useState, useMemo, defined outside of this component, etc.)
    mantineTableHeadRowProps: row =>({
      className: 'my-custom-class',
    }),
  });

  return <MantineReactTable table={table} />;
};
@alessandrojcm alessandrojcm added the V2 Issue with MRT V2 label Feb 3, 2024
Repository owner locked and limited conversation to collaborators Jun 10, 2024
@alessandrojcm alessandrojcm converted this issue into discussion #352 Jun 10, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
V2 Issue with MRT V2
Projects
None yet
Development

No branches or pull requests

2 participants