react-custom-scrollbars icon indicating copy to clipboard operation
react-custom-scrollbars copied to clipboard

Scrollbars are rejected in MaterialUI Tables

Open lotusms opened this issue 7 years ago • 7 comments

When used in a material UI TableBody, it seems that MaterialUI rejects anything that may alter their table's architecture throught the DOM. Material UI forbids using anything other than TableHeader or TableBody as Table children, and any

inside of TableBody or Table Header (per HTML5 standars, this is not permitted either)

<Scrollbars> render as a div.

Is there a way to assign Scrollbars to the TableBody without using the <Scrollbars> so that way the Table architecture is unchanged?

Here is the code

    `<TableBody
	displayRowCheckbox={this.state.showCheckboxes}
	deselectOnClickaway={this.state.deselectOnClickaway}
	showRowHover={this.state.showRowHover}>
    	<Scrollbars  //not permitted. it renders as a <div>
    		autoHide={false}
    		style={ScrollBarsStyle}>
		{tableData.map( (row, index) => (
			<TableRow key={index}>
				<TableRowColumn>{row.name}</TableRowColumn>
				<TableRowColumn>{row.type}</TableRowColumn>
				<TableRowColumn>{row.owner}</TableRowColumn>
			</TableRow>
		))}
    	</Scrollbars>
    </TableBody>` 

UPDATE The only way it can work is by adding the entire table inside the Scrollbars tags. But it disables the fixedHeader.

lotusms avatar May 15 '17 17:05 lotusms

This can be accomplished by using two material-ui tables. One for the header and one for the rows.

<Table>
  <TableHeader>
  ...
  </TableHeader>
</Table>
<Scrollbars>
  <Table>
    <TableBody>
     ...
    </TableBody>
  </Table>
</Scrollbars>

alexlukelevy avatar May 19 '17 13:05 alexlukelevy

Yup! That did it! Thank you!

lotusms avatar May 19 '17 20:05 lotusms

But what if you need the columns to be the same width?

sarahshuffle avatar Jul 11 '17 09:07 sarahshuffle

Then give the both sets of columns a style property e.g. style={{ width: '10%' }}

alexlukelevy avatar Jul 12 '17 18:07 alexlukelevy

Unideal solution. What if you want the header to be fixed on vertical scroll, however to scroll with the content on horizontal scroll.

edit: Seems the only way to go about it might be a modified version of what you have there combined with js to move the tablehead left or right.

justinmasse avatar Aug 25 '17 16:08 justinmasse

How would the horizontal scrolling work in this case? @justinmasse did you get this to work?

carlosafw avatar Feb 11 '19 17:02 carlosafw

@justinmasse, @carlosafw just put both tables inside a horizontally scrollable div

TassosD avatar Nov 26 '20 16:11 TassosD