eugenekr
eugenekr

Reputation: 6602

How can I add custom attribute to MUI DataGrid Column Header?

I need to add data-test attribute to column header for automated testing of different operations, such as sorting, filtering etc., so that scripts could find where to click.

How it can be done? I would like to keep all the functionality of default headers, just add the attribute.

Thanks!

Upvotes: 0

Views: 2082

Answers (1)

Akis
Akis

Reputation: 2252

You can use the renderHeader and pass the attributes you want like below:

        columns={[
          {
            field: "name",
            renderHeader: (params) => (
              <span data-testid="header-test-id"> // Here pass your data-testid
                {"Header with attr "}
              </span>
            )
          }
        ]}

Upvotes: 2

Related Questions