MTableToolbar
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 },
]}
components={{
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 },
]}
components={{
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>
);
}
}}
/>
)
}