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

[Table] Allow multiple header rows (Group) #17909

Closed
1 task done
rodmansw opened this issue Oct 16, 2019 · 8 comments · Fixed by #17933
Closed
1 task done

[Table] Allow multiple header rows (Group) #17909

rodmansw opened this issue Oct 16, 2019 · 8 comments · Fixed by #17933
Labels
component: table This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process. hacktoberfest https://hacktoberfest.digitalocean.com/

Comments

@rodmansw
Copy link

It would be great if you could add possibility to have multiple header rows

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

The output table should have multiple header rows, it should look something like this:

Motivation 🔦

I need this to see how an item behaved in time

     |     Date 1    |     Date 2    | ...
Item | price | sales | price | sales | ... 
@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 16, 2019

What about?

import React from 'react';
import { makeStyles } from '@mui/material/styles';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Paper from '@mui/material/Paper';

const useStyles = makeStyles({
  root: {
    width: '100%',
    overflowX: 'auto',
  },
  table: {
    minWidth: 650,
  },
});

function createData(name: string, calories: number, fat: number, carbs: number, protein: number) {
  return { name, calories, fat, carbs, protein };
}

const rows = [
  createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
  createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
  createData('Eclair', 262, 16.0, 24, 6.0),
  createData('Cupcake', 305, 3.7, 67, 4.3),
  createData('Gingerbread', 356, 16.0, 49, 3.9),
];

export default function SimpleTable() {
  const classes = useStyles();

  return (
    <Paper className={classes.root}>
      <Table className={classes.table} aria-label="simple table">
        <TableHead>
          <TableRow>
            <TableCell />
            <TableCell align="center" colSpan={2}>
              Data 1
            </TableCell>
            <TableCell align="center" colSpan={2}>
              Data 2
            </TableCell>
          </TableRow>
          <TableRow>
            <TableCell>Dessert (100g serving)</TableCell>
            <TableCell align="right">Calories</TableCell>
            <TableCell align="right">Fat&nbsp;(g)</TableCell>
            <TableCell align="right">Carbs&nbsp;(g)</TableCell>
            <TableCell align="right">Protein&nbsp;(g)</TableCell>
          </TableRow>
        </TableHead>
        <TableBody>
          {rows.map(row => (
            <TableRow key={row.name}>
              <TableCell component="th" scope="row">
                {row.name}
              </TableCell>
              <TableCell align="right">{row.calories}</TableCell>
              <TableCell align="right">{row.fat}</TableCell>
              <TableCell align="right">{row.carbs}</TableCell>
              <TableCell align="right">{row.protein}</TableCell>
            </TableRow>
          ))}
        </TableBody>
      </Table>
    </Paper>
  );
}

Capture d’écran 2019-10-16 à 23 25 50

@oliviertassinari oliviertassinari added the component: table This is the name of the generic UI component, not the React module! label Oct 16, 2019
@rodmansw
Copy link
Author

This can work. Didn't know you can put two TableRow in a TableHead I will try it

Thanks!

Also I think this have to be part of the docs

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Oct 17, 2019
@oliviertassinari
Copy link
Member

Agree, it's something to document, and potentially to improve the UI.

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label Oct 17, 2019
@daini-rl
Copy link

Hi (: I tried to do it with my example but a white line appeared between the head rows... tried to change the theme, even styles and got nothing... any advice?
Screenshot from 2019-10-17 12-10-17
The same with the example edited in CodeSandbox
Screenshot from 2019-10-17 12-13-41

@daini-rl
Copy link

daini-rl commented Oct 17, 2019

I finally found the solution, It was that tiny pixel...

MuiTableCell: {
      head: {
        borderBottom: 0
      }
}

@adeelibr
Copy link
Contributor

Agree, it's something to document, and potentially to improve the UI.

Can I add a new demo with multiple Table header rows, if that's okay? @oliviertassinari

@rayy-lo
Copy link
Contributor

rayy-lo commented Oct 18, 2019

Hello! Is anyone working on this? This is my first contribution and would like to give this a shot.

@oliviertassinari
Copy link
Member

Note that we have a higher level API in the pipeline for column grouping: mui/mui-x#195.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: table This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process. hacktoberfest https://hacktoberfest.digitalocean.com/
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants