Mui-datatables: Support Fixed Columns?

Created on 23 Oct 2018  Â·  11Comments  Â·  Source: gregnb/mui-datatables

Is there a support for fixed columns?

Fixed columns are useful when you have a very large horizontally spanning table and you want to have some columns on the left or the right fixed for easier viewing.

It would be awesome if there was a prop for columns like fixed, that takes in a string value of "left" or "right" or null. And have the specified columns be fixed on the left side or the right side.

enhancement

Most helpful comment

As a workaround, you can manually set the proper position: sticky css to the table cells and the header. It's not pretty but works:

import { TableCell } from "@material-ui/core";

const style = {
  position: "sticky",
  left: 0,
  background: "white",
  zIndex: 101
};

const columns = [
  {
    name: "Name",
    options: {
      customHeadRender: () => (
        <TableCell key="name" style={{ ...style, top: 0, zIndex: 102 }}>
          Name
        </TableCell>
      ),
      setCellProps: () => ({ style })
    }
  },
  "Title",
  "Location"
];

POC codesandbox for reference: https://codesandbox.io/s/rrr9zw4pwo

All 11 comments

Are you watching me? I better check for you in my closet. Hah, all jokes aside I literally just pushed up part one to this. So far it’s enabled for the header itself and I’ll add something for the individual columns. It’ll be an enum property something like

fixed: (‘left’, ‘right’)

That's a great news. Closing this issue as it is in progress now. Thanks.

Was this implemented ? I didn't saw any reference

Any update on this?

Any update on fixing first column even with createMuiTheme ?

I'm interested in this functionality too. Updates?

As a workaround, you can manually set the proper position: sticky css to the table cells and the header. It's not pretty but works:

import { TableCell } from "@material-ui/core";

const style = {
  position: "sticky",
  left: 0,
  background: "white",
  zIndex: 101
};

const columns = [
  {
    name: "Name",
    options: {
      customHeadRender: () => (
        <TableCell key="name" style={{ ...style, top: 0, zIndex: 102 }}>
          Name
        </TableCell>
      ),
      setCellProps: () => ({ style })
    }
  },
  "Title",
  "Location"
];

POC codesandbox for reference: https://codesandbox.io/s/rrr9zw4pwo

Looks like that works for a single stickied column, but not multiple.

+1 for stickied column functionality.

That's a great news. Closing this issue as it is in progress now. Thanks.
Do you know if we got the fixed columns checked in as well ?

As a workaround, you can manually set the proper position: sticky css to the table cells and the header. It's not pretty but works:

import { TableCell } from "@material-ui/core";

const style = {
  position: "sticky",
  left: 0,
  background: "white",
  zIndex: 101
};

const columns = [
  {
    name: "Name",
    options: {
      customHeadRender: () => (
        <TableCell key="name" style={{ ...style, top: 0, zIndex: 102 }}>
          Name
        </TableCell>
      ),
      setCellProps: () => ({ style })
    }
  },
  "Title",
  "Location"
];

POC codesandbox for reference: https://codesandbox.io/s/rrr9zw4pwo

I implemented this code to my project and it works well, but I want to give different background color for odd and even rows, how can I do that?

Please Refer to #201 for striped rows.

Also for the newer release, setting style is sufficient for fixing the columns.

  setCellProps: () => ({ style: {
             position: "sticky",
             left: 0,
             background: "white",
             zIndex: 101
  }}),
  setCellHeaderProps: () => ({ style: {
              position: "sticky",
              left: 0,
              top: 0, //Incase Header is Fixed
              background: "blue",
              zIndex: 102
  }})
Was this page helpful?
0 / 5 - 0 ratings

Related issues

T-pirithiviraj picture T-pirithiviraj  Â·  3Comments

ronaiza-cardoso picture ronaiza-cardoso  Â·  3Comments

geekashu picture geekashu  Â·  3Comments

aramkoukia picture aramkoukia  Â·  3Comments

gangakrishh picture gangakrishh  Â·  3Comments