mbrn / material-table

Datatable for React based on material-ui's table with additional features

Home Page:https://material-table.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How update table styling after sorting?

gabrielizalo opened this issue · comments

I created a Zebra Table with sort columns:

CleanShot 2023-07-26 at 11 21 12@2x

The did setup the zebra style in this way:


<MaterialTable
  data={data}
  columns={columns}
  ...
  options={{
    ...
    rowStyle: (rowData) => ({
      backgroundColor:
        rowData.tableData.id % 2 === 0
          ? "var(--white)"
          : "var(--wild-sand)",
    }),
  }}
/>

After sorting, the background colors remains in the original rows, so the table is not a zebra table anymore:

CleanShot 2023-07-26 at 11 24 17@2x

How I can update the "zebra styling" of the table after sorting?

Thanks

The solution was very easy as pointed here: material-table-core/core#781 (comment)