I'm using react material-table and want to override default styles of toolbar to pass the prop disableGutters={true} as we can do in material-ui toolbar . Here is my code
<MaterialTable
// other props
ponents={{
Toolbar: (props) => {
return (
<div>
<MTableToolbar {...props} style={{paddingLeft:"0px"}}/>
</div>
);
},
}}
/>
But it's not working to remove gutter padding. I also tried <MTableToolbar {...props} disableGutters={true}/>
but nothing works.
I'm using react material-table and want to override default styles of toolbar to pass the prop disableGutters={true} as we can do in material-ui toolbar . Here is my code
<MaterialTable
// other props
ponents={{
Toolbar: (props) => {
return (
<div>
<MTableToolbar {...props} style={{paddingLeft:"0px"}}/>
</div>
);
},
}}
/>
But it's not working to remove gutter padding. I also tried <MTableToolbar {...props} disableGutters={true}/>
but nothing works.
1 Answer
Reset to default 5MTableToolbar
has these classes MuiToolbar-root MuiToolbar-regular MuiToolbar-gutters
. You can override these in this way by using @material-ui/styles
. Install it first, npm install @material-ui/style
. Then follow the code below:
import React from 'react';
import MaterialTable, { MTableToolbar } from 'material-table';
import { makeStyles } from '@material-ui/core/styles';
const useStyles = makeStyles({
toolbarWrapper: {
'& .MuiToolbar-gutters': {
paddingLeft: 0,
paddingRight: 0,
}
},
});
export default function App() {
const classes = useStyles();
return (
<MaterialTable
title="Toolbar Overriding Preview"
columns={[
{ title: 'Name', field: 'name' },
{ title: 'Surname', field: 'surname' },
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
{
title: 'Birth Place',
field: 'birthCity',
lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
},
]}
data={[
{ name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
{ name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
]}
ponents={{
Toolbar: props => (
<div className={classes.toolbarWrapper}><MTableToolbar {...props} /></div>
),
}}
/>
)
}
Alternative Solution:
There is another way you can use your own title rather than overriding the original one.
You have to copy props to hide the default title and show your own.
Use Grid
with the MTableToolbar
so they still appear next to each other.
Here is the code:
import React from 'react';
import MaterialTable, { MTableToolbar } from 'material-table';
import { Grid } from '@material-ui/core';
export default function App() {
return (
<MaterialTable
title="Toolbar Overriding Preview"
columns={[
{ title: 'Name', field: 'name' },
{ title: 'Surname', field: 'surname' },
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
{
title: 'Birth Place',
field: 'birthCity',
lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
},
]}
data={[
{ name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
{ name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
]}
ponents={{
Toolbar: props => {
// This will let you use your own Title while keeping the search
const propsCopy = { ...props };
// Hide default title
propsCopy.showTitle = false;
return (
<Grid container direction="row">
<Grid item xs={6}>
<h2>Your Own Title</h2>
</Grid>
<Grid item xs={6}>
<MTableToolbar {...propsCopy} />
</Grid>
</Grid>
);
}
}}
/>
)
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745492500a4630047.html
评论列表(0条)