gregnb / gregnb/mui-datatables

Duplicate classes for <td> and <div> in table cells

Open
#1,768 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.7k
Forks
906
PR merge metrics
No merged PRs in 30d

Description

Hi!

I have upgraded mui-datatables: 2.12.0 -> 3.7.8. I found some breaking changes messing up our layouts in a huge frontend application. The reason is the new inner div element that is now rendered inside the table cell, while also receiving the same classes as the conatining element from `setCellProps`. This is problematic for styles like padding and border, where paddings double up, and inner borders appear.

Layout after upgrading:
![image](https://user-images.githubusercontent.com/56896763/130968173-aa59e2e7-e322-4243-8b99-af1f78ef23c6.png)

Layout when I remove the inner divs with the duplicate classes (with inspector):
![image](https://user-images.githubusercontent.com/56896763/130968668-55226a25-1645-4074-94ba-911f97cf06fe.png)

## Expected Behavior

When rendering the table,
- there should be no inner div elements, as it was before. I could not find any reason in the history for this change.
- OR the divs should not receive the same classes as the td elements from `setCellProps`
- OR there should be a way to specify classes for the td and the inner div element

---
*EDIT*
## Current Behavior
I tried to reproduce the issue in the code sandbox. I have found out, that if I set the styles property with setCellProps, than the divs do not receive the styles, but when setting the className, both the div and the td element receive it.

```jsx
import React from "react";
import ReactDOM from "react-dom";
import MUIDataTable from "mui-datatables";

import makeStyles from '@material-ui/styles/makeStyles';

const myStyles = {
padding: 8,
border: '1px solid black'
};

const useStyles = makeStyles(() => ({
test: myStyles,
}))

function App() {
const classes = useStyles();
const columns = [{name: "Name", options: {
setCellProps: (_, index) => (index % 2 === 0 ? { style: myStyles } : { className: classes.test })
}}];

const options = {
filter: true,
filterType: "dropdown",
};

const data = [
["Gabby Georgee", "Business Analyst", "Minneapolis"],
[
"Aiden Lloyd",
"Business Consultant for an International Company and CEO of Tony's Burger Palace",
"Dallas"
],
["Jaden Collins", "Attorney", "Santa Ana"],
["Franky Rees", "Business Analyst", "St. Petersburg"],
["Aaren Rose", null, "Toledo"],
["Johnny Jones", "Business Analyst", "St. Petersburg"],
["Jimmy Johns", "Business Analyst", "Baltimore"],
["Jack Jackson", "Business Analyst", "El Paso"],
["Joe Jones", "Computer Programmer", "El Paso"],
["Jacky Jackson", "Business Consultant", "Baltimore"],
["Jo Jo", "Software Developer", "Washington DC"],
["Donna Marie", "Business Manager", "Annapolis"]
];

return (



);
}

ReactDOM.render(, document.getElementById("root"));
```
Top highlight:
`setCellProps: (_, index) => (index % 2 === 0 ? { style: myStyles } : { className: classes.test })`
![image](https://user-images.githubusercontent.com/56896763/130972401-2ba22256-b5c3-4d82-b4e0-5ca5b2e5bdb0.png)

*EDIT 2*
Removing lines https://github.com/gregnb/mui-datatables/blob/master/src/components/TableBodyCell.js#L146 https://github.com/gregnb/mui-datatables/blob/master/src/components/TableBodyCell.js#L167 solves the problem, I have checked in a code sandbox.
## Your Environment

| Tech | Version |
|--------------|---------|
| Material-UI | 4.11 |
| MUI-datatables | 3.7.8 |
| React | 16.8 |
| browser | chrome |

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/components/TableBodyCell.js at the referenced lines 146 and 167, then reproduce the issue with the provided setCellProps example in a code sandbox. Verify how className and style are applied to the td and inner div. Done means class-based cell props no longer create the reported duplicate layout effects, with the existing behavior preserved for styles.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.