I am using the Table
component from the react
library material-ui
.
For some reason, each row, including the header, has a 24px
padding, top and bottom, which I can't override.
I already tried changing the style on all the underlying components with no success. Here is the code:
<Table>
<TableHeader adjustForCheckbox={false} displaySelectAll={false} fixedHeader={true}>
<TableRow>
<TableHeaderColumn>id</TableHeaderColumn>
<TableHeaderColumn>name</TableHeaderColumn>
<TableHeaderColumn>number</TableHeaderColumn>
</TableRow>
</TableHeader>
<TableBody showRowHover={true} displayRowCheckbox={false}>
{data.map(item => {
return (
<TableRow key={item.id}>
<TableRowColumn>{item.id}</TableRowColumn>
<TableRowColumn>{item.name}</TableRowColumn>
<TableRowColumn>{item.number}</TableRowColumn>
</TableRow>
);
})}
</TableBody>
</Table>
Any idea how which component's style needs to be changed in order to override this styling?
Set Material-UI Table Row Height with Class Override. I will override the TableRow in the TableHead using class based overrides. There are two steps to this for the Table component: set a height in the TableRow, and remove the vertical padding in the TableCell.
As shown in the previous section, simply use the style or classes prop on the TableCell to set the width, i.e. style={{ width: "25%" }} .
Show activity on this post. Create the list beforehand in the build method. final rows = <TableRow>[]; for (var rowData in myRowDataList) { rows. add(TableRow( ... // Generate a TableRow using rowData )); } ... Table( columnWidths: { 0: FlexColumnWidth(1.0), 1: FlexColumnWidth(2.0), }, border: TableBorder.
The Stack component manages layout of immediate children along the vertical or horizontal axis with optional spacing and/or dividers between each child.
This kind of requirements can be handled with overrides in Material UI as per below example:
Step 1: include following dependencies
import { ThemeProvider } from '@material-ui/core'
import { createMuiTheme } from '@material-ui/core/styles';
Step 2: Define custom css related changes as
const theme = createMuiTheme({
overrides: {
MuiTableCell: {
root: { //This can be referred from Material UI API documentation.
padding: '4px 8px',
backgroundColor: "#eaeaea",
},
},
},
});
Step 3: Wrap your component or your code block with
<ThemeProvider theme={theme}>
<Table>
<TableRow>
<TableCell component="td" scope="row">
</TableCell>
</TableRow>
</Table>
</ThemeProvider>
This is how we can override the Material UI style from our custom style. Happy Coding :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With