Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material Table is not responsive #1395

Closed
kkateli opened this issue Nov 28, 2019 · 35 comments
Closed

Material Table is not responsive #1395

kkateli opened this issue Nov 28, 2019 · 35 comments
Labels
enhancement New feature or request feature help wanted Extra attention is needed wontfix This will not be worked on

Comments

@kkateli
Copy link

kkateli commented Nov 28, 2019

Material Table is not responsive. It only reduces the width of the table when shrinking a page. A lot of other table libraries create "stacked" table in mobile view (e.g. https://github.com/gregnb/mui-datatables). Is it possible to have this stacked table view in the near future? I reckon It would be nice to swap the table to Material UI list in mobile view.

Taken from:MUI datatables

Screen Shot 2019-11-28 at 2 38 21 PM

@abhishekgupta92
Copy link

Any visibility on this whether this is going to be implemented in the library sooner or later?

@JeffEmery
Copy link

What to do here... I don't see this lib having it's own responsive solution. I mean what would it look like? It would depend on the very instance of the table that needs to be rendered on a small screen. User preferences would undoubtedly cause all kinds of issues.

The only reasonable solution I can see is to implement horizontal scroll at some min width similar to material-ui table.

I like @kkateli idea of using a material-ui list to display an alternate view. Probably can do this pretty easily, but with significant drop in usability. e.g. sorting. Search might not be too bad. And list can be virtualized with react window

Anyway I think rolling your own mobile display is the better solution, with horizontal scroll being a best solution for this library.

@JeffEmery
Copy link

Horizontal scroll is apparently the default behavior already. I'll have to see why it's not scrolling on my table.

@hatchli
Copy link

hatchli commented Apr 19, 2020

@JeffEmery Mine is not horizontal scrolling either. Did you figure out what was disabling it?

@LuanScudeler
Copy link

@JeffEmery @hatchli Mine was not scrolling because the table was under a display: flex way up in the DOM tree of my layout. For me, horizontal scrolling only worked under a display: block

I wonder if it's possible to still make it horizontal scrollable with display: flex, that would be good because I had to do some undesired chages to my page layout because of the display: block

@JeffEmery
Copy link

@hatchli I think I had the same issue as @LuanScudeler . Once I dismantled all the containers above the table, the horizontal scroll began working. I didn't narrow it down to display: flex like @LuanScudeler but I highly suspect that was the same issue.

@oze4 oze4 added enhancement New feature or request feature help wanted Extra attention is needed labels May 31, 2020
@a-tonchev
Copy link

Is there any progress on this issue? horizontal scrolling is really ugly on mobile and I really like material-table and don't want to switch.

@stale
Copy link

stale bot commented Oct 15, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

@stale stale bot added the wontfix This will not be worked on label Oct 15, 2020
@influentcoder
Copy link

Bump

@stale stale bot removed the wontfix This will not be worked on label Oct 19, 2020
@anmolmalik97
Copy link

anmolmalik97 commented Nov 6, 2020

any updates?
@mbrn any plans to implement this?

@JeremyEnglert
Copy link

What to do here... I don't see this lib having it's own responsive solution. I mean what would it look like? It would depend on the very instance of the table that needs to be rendered on a small screen. User preferences would undoubtedly cause all kinds of issues.

Check out mui-datatables. They handle responsiveness very well! Would love to see something similar implemented in this library.

@hutber
Copy link

hutber commented Jan 5, 2021

I'm also having this same issues. Changing tables at this point is less than desirable though :D

@gatz2
Copy link

gatz2 commented Mar 9, 2021

no updates?

@prempro42
Copy link

prempro42 commented Mar 10, 2021

Material Table is not responsive. It only reduces the width of the table when shrinking a page. A lot of other table libraries create "stacked" table in mobile view (e.g. https://github.com/gregnb/mui-datatables). Is it possible to have this stacked table view in the near future? I reckon It would be nice to swap the table to Material UI list in mobile view.

Taken from:MUI datatables

Screen Shot 2019-11-28 at 2 38 21 PM

Yes!! this would be so much better & helpful! I support the stack implementation for mobile view

@ravieway
Copy link

Still no update I guess

@gbdav2
Copy link

gbdav2 commented Apr 28, 2021

Any update?

@btechn01
Copy link

@kadirtereci
Copy link

any update?

@BugraTuncer
Copy link

Updates?

@kadirtereci
Copy link

Updates?

still no update...

@thepasterover
Copy link

Im really surprised this is not a feature in Material UI and it's problematic to see no further updates on this issue. Even Vuetify which is modelled after Material UI in its early versions has this feature. Hope Dev's notice this.

@joeflatt
Copy link

@JeffEmery @hatchli @LuanScudeler... Regarding horizontal scroll within a display: flex container, another workaround is to use min-width: 0 on your flex container instead of changing to display: block.

@NikhilChugh
Copy link

NikhilChugh commented Jul 30, 2021

If someone is still facing this issue.. I did it this way
Wrap the material table with fieldset tag (hide its boundary using border: none)

<fieldset style={border: 'none'}>
 <MaterialTable
...otherData,
style={maxWidth: '90vw', overflow: 'auto'}.      // maxWidth adjust according to screen
 />
</fieldset>

Also give individual headerStyle: {width: ''} to each column header in 'px' to exceed total beyond screen size.

My material table version is "material-table": "^1.54.1",

@kadirtereci
Copy link

@NikhilChugh Can you share full code example? I tried your solution but it is not working for me

@NikhilChugh
Copy link

@kadirtereci check this code
`
import React, {useState} from 'react';
import MaterialTable from 'material-table';

function Editable() {

const [columns, setColumns] = useState([
{ title: 'Name', field: 'name', headerStyle: {width: '500px'} },
{ title: 'Surname', field: 'surname', initialEditValue: 'initial edit value', headerStyle: {width: '500px'} },
{ title: 'Birth Year', field: 'birthYear', type: 'numeric', headerStyle: {width: '500px'} },
{
title: 'Birth Place',
field: 'birthCity',
lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
headerStyle: {width: '500px'}
},
]);

const [data, setData] = useState([
{ name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
{ name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
]);

return (
<fieldset style={{padding: '0px', border: 'none'}}>
<MaterialTable
title="Editable Preview"
columns={columns}
style={{maxWidth: '97vw', overflow: 'scroll'}}
data={data}
editable={{
onRowAdd: newData =>
new Promise((resolve, reject) => {
setTimeout(() => {
setData([...data, newData]);

          resolve();
        }, 1000)
      }),
    onRowUpdate: (newData, oldData) =>
      new Promise((resolve, reject) => {
        setTimeout(() => {
          const dataUpdate = [...data];
          const index = oldData.tableData.id;
          dataUpdate[index] = newData;
          setData([...dataUpdate]);

          resolve();
        }, 1000)
      }),
    onRowDelete: oldData =>
      new Promise((resolve, reject) => {
        setTimeout(() => {
          const dataDelete = [...data];
          const index = oldData.tableData.id;
          dataDelete.splice(index, 1);
          setData([...dataDelete]);
          
          resolve()
        }, 1000)
      }),
  }}
/>
</fieldset>

)
}

export default Editable;

`

This will only make material table horizontally scrollable. Hope it helps

@hamid842
Copy link

hamid842 commented Aug 3, 2021

I had the same issue, but did like this:
`import React from "react";
import MaterialTable from "material-table";
import "./App.css";
import {
ThemeProvider,
useTheme,
createTheme,
makeStyles,
} from "@material-ui/core/styles";
import { Grid, Typography } from "@material-ui/core";
import useMediaQuery from "@material-ui/core/useMediaQuery";

const useStyles = makeStyles((theme) => ({
titleContainer: {
[theme.breakpoints.up("sm")]: {
display: "none",
},
},
title: {
fontWeight: 700,
},
}));

const theme = createTheme();

function App() {
function useWidth() {
const theme = useTheme();
const keys = [...theme.breakpoints.keys].reverse();
return (
keys.reduce((output, key) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const matches = useMediaQuery(theme.breakpoints.up(key));
return !output && matches ? key : output;
}, null) || "xs"
);
}

const width = useWidth();
const classes = useStyles();
return (

<MaterialTable
title="Action Overriding Preview"
// style={classes.table}
columns={[
{
title: "Name",
field: "name",
align: "left",
render: (rowData) => (


Name:


{rowData.name}


),
cellStyle:
width === "xs"
? {
width: "100%",
display: "flex",
flexDirection: "column",
borderBottom: 0,
}
: {},
},
{
title: "Surname",
field: "surname",
align: "left",
render: (rowData) => (


Surname:


{rowData.surname}


),
cellStyle:
width === "xs"
? {
width: "100%",
display: "flex",
flexDirection: "column",
borderBottom: 0,
}
: {},
},
{
title: "Birth Year",
field: "birthYear",
type: "numeric",
align: "left",
render: (rowData) => (


Birth Date:


{rowData.birthYear}


),
cellStyle:
width === "xs"
? {
width: "100%",
display: "flex",
flexDirection: "column",
borderBottom: 0,
}
: {},
},
{
title: "Birth Place",
field: "birthCity",
lookup: { 34: "İstanbul", 63: "Şanlıurfa" },
align: "left",
render: (rowData) => (


Birth City:


{rowData.birthCity}


),
cellStyle:
width === "xs"
? {
width: "100%",
display: "flex",
flexDirection: "column",
borderBottomWidth: 2,
}
: {},
},
]}
data={[
{ name: "Mehmet", surname: "Baran", birthYear: 1987, birthCity: 63 },
{
name: "Zerya Betül",
surname: "Baran",
birthYear: 2017,
birthCity: 34,
},
{
name: "Zerya Betül",
surname: "Baran",
birthYear: 2017,
birthCity: 34,
},
]}
options={{
emptyRowsWhenPaging: false,
search: false,
rowStyle:
width === "xs"
? {
width: "100%",
display: "flex",
flexDirection: "column",
}
: {},
headerStyle:
width === "xs"
? {
display: "none",
}
: {},
}}
actions={[
{
icon: "save",
tooltip: "Save User",
onClick: (event, rowData) => alert("You saved " + rowData.name),
},
]}
/>

);
}

export default App;
`

if you want to make component smaller you can create reusable component for each column "render" and even make this MaterialTable component reusable.

@stale
Copy link

stale bot commented Nov 1, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

@stale stale bot added the wontfix This will not be worked on label Nov 1, 2021
@archfz
Copy link

archfz commented Nov 3, 2021

Bump.

@stale stale bot removed the wontfix This will not be worked on label Nov 3, 2021
@nuggetsnetwork
Copy link

Cant believe there is no formal solution to this since.

@abdennour
Copy link

i cannot believe. But this is the reality : (

@kfw9257
Copy link

kfw9257 commented Mar 7, 2022

Any update on this issue?

@archfz
Copy link

archfz commented Mar 7, 2022

Give a try on https://github.com/archfz/vh-sticky-table-header . This allows for both sticky header and also horizontal scrolling on mobile (it doesn't use display sticky, to support on parents different displays and overflows).

@fappaz
Copy link

fappaz commented Mar 23, 2022

Alternatively, material-table could have the built-in capability to render each row as a different component on shorter widths, like bootstrap-table:

boostrap-table-responsiveness

I understand some existing features (e.g. grouping?) might be challenging to implement with this approach, so a good idea would be to empower the developers to render their own responsive row, as long as the component has access to the row data and table state:

<MaterialTable
  title="Users"
  data={users}
  columns={[
    { title: "Name", field: "name" },
    { title: "Email", field: "email" },
  ]}
  components={{
    ResponsiveRow: ({ rowData, state }) => <UserCard user={rowData}  />
  }}
/>

What are your thoughts?

@stale
Copy link

stale bot commented Jun 23, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

@stale stale bot added the wontfix This will not be worked on label Jun 23, 2022
@stale stale bot closed this as completed Jul 10, 2022
@MohammedSaberMohammed
Copy link

For Any one having this issue just use the following

    const tableStyle = {
         overflow: 'auto' // scroll
     };

   <div style={{ display: 'grid' }}> // ===> grid
      <MaterialTable
         style={tableStyle}
       />
  </div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature help wanted Extra attention is needed wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests