admin管理员组文章数量:1022688
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>
);
}
}}
/>
)
}
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>
);
}
}}
/>
)
}
本文标签: javascriptHow to apply disableGutters props on MTableToolbarStack Overflow
版权声明:本文标题:javascript - How to apply disableGutters props on MTableToolbar? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745492497a2153023.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论