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

[TableRowColumn] When using a wrapped TableRowColumn, nothing renders

Open Reinami opened this issue 9 years ago • 3 comments

Problem description

I have a code snippet where basically i have a Table that looks something like this:

render () {
const { isMultiSelectable } = this.props
<Table
  multiSelectable={isMultiSelectable}
  onRowSelection={this.onRowSelection}
>
  <TableBody
     displayRowCheckbox={isMultiSelectable}
     deselectOnClickaway={false}
     showRowHover={false}
  >
     {this.generateTableRows()}
  </TableBody>
</Table>
}

Inside of the "generateTableRows method, i return an array of rows that looks like this:

<TableRow selected={isSeleted}, selectable={isSelectable}>
  {this.generateTableCells()}
</TableRow>

Inside of generateTable Cells, i do similar to above, i generate an array of tableCells, which are a custom component that, can render either a spinner (if data is loading) or another component that wraps TableRowColumn to display some data

When doing this, i receive an error:

Warning: Material-UI: Children of the Table component must be TableBody or TableHeader or TableFooter.
Nothing is rendered.

I was previously using an older version of Material-UI where this was working fine, back in version 0.14.4 where things were working fine, but upon upgrading i can't seem to get my tables to render due to this error.

Versions

  • Material-UI: 0.17.1
  • React: 15.4.2
  • Browser: Chrome

Reinami avatar Apr 11 '17 22:04 Reinami

Might also be somewhat related to the issue that i've opened https://github.com/callemall/material-ui/issues/6556 Try to put the whole table generation in the same place, meaning without using the generate functions, see if that works first

slavab89 avatar Apr 12 '17 07:04 slavab89

I got the same error message when I was using an own component for <TableBody> like:

<Table>
  <TableHeader />
  <MyCustomTableBody />
</Table>

Analyzing the check which is done in https://github.com/callemall/material-ui/blob/master/src/Table/Table.js#L251 I set a static variable in my custom component like so (probably it's not the cleanest solution) and furthermore I pass down all non custom props to the actual <TableBody> in order to prevent event swallowing.


export default class MyCustomTableBody extends Component {
  static muiName = 'TableBody';
  ...
  render() {
    const {customPropA, customPropB, ...props} = this.props;
    return (
      <TableBody {...props}/>
    );
  }
}

davincho avatar Apr 12 '17 08:04 davincho

We have been porting the component on the v1-beta branch. We reimplemented it from the ground-up. While we haven't tested it, I think that the issue is most likely fixed on that branch. Hence, I'm closing it. Still, we will accept PR fixes until v1-beta takes over the master branch.

oliviertassinari avatar Aug 05 '17 06:08 oliviertassinari