material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Fixed Columns

Open francesco-clementi opened this issue 7 years ago • 12 comments

Is there a way to fix the position of the first column in a table with over 40 columns?

francesco-clementi avatar Jun 26 '19 12:06 francesco-clementi

Created a PR for this feature. What do you think about it?

dnn5b avatar Sep 06 '19 12:09 dnn5b

Hi dnn5b, actually I was looking for another kind of fixed columns.

As shown in the attachment, I'd like to fixed the column when I use the stick on the down.

I'd like that when I'm scrolling right I can be able to still see the first columns.

image

francesco-clementi avatar Sep 06 '19 13:09 francesco-clementi

I was able to fix the first column (action column) by applying some CSS.

const useStyles = makeStyles({
  stickyActionsColumn: {
    '& table:first-child': {
      '& tr': {
        '& td:first-child, th:first-child': {
          backgroundColor: '#f5f5f5',
          position: 'sticky',
          left: 0,
          zIndex: 999
        },
        '& th:first-child': {
          zIndex: 9999
        }
      }
    }
  }
})

ShevaShen avatar Sep 11 '19 23:09 ShevaShen

Hi @ShevaShen , thanks for your support, but I'm a beginner in styling.

I'm not using hooks in react, but I'm using material-table in a class component. My first column "action" is not custom, but it's from the editable feature of material-table "https://material-table.com/#/docs/features/editable".

Please could you help me to integrate your solution in mine?

Thanks

francesco-clementi avatar Sep 12 '19 08:09 francesco-clementi

@francesco-clementi-bip here is the sass snippet. Place the table component inside <div className="table-container"></div>

.table-container {
  table:first-child {
    tr {
      td:first-child, th:first-child {
        background-color: '#f5f5f5';
        position: 'sticky';
        left: 0;
        z-index: 999;
      }
      th:first-child {
        z-index: 9999;
      }
    }
  }
}

ShevaShen avatar Sep 12 '19 21:09 ShevaShen

@ShevaShen I tried your method it's working. Thank you very much! I suppose fixed head can apply for the same thing :)

didopop3 avatar Sep 13 '19 06:09 didopop3

@ShevaShen thanks sheva, your help is really appreciated,. I managed to fixed the header of the actions column. Could it be possibile to fix not only the header, but the whole column?

francesco-clementi avatar Sep 16 '19 10:09 francesco-clementi

@francesco-clementi-bip if you apply the style to the parent div of the table, this should fix the whole first column

ShevaShen avatar Sep 22 '19 02:09 ShevaShen

https://material-table.com/#/docs/features/fixed-columns Seems to be solved?

codenamethanos avatar Feb 11 '20 05:02 codenamethanos

right, saw it in the new release https://github.com/mbrn/material-table/issues/43

ShevaShen avatar Feb 12 '20 00:02 ShevaShen

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[bot] avatar Jul 05 '20 22:07 stale[bot]

looking for same solution with sticky header any suggestion?

javed-ahmad avatar Jun 23 '21 14:06 javed-ahmad