I'm creating a table in react (new to react), but the CategoryData is not creating cells correctly, i.e. it's creating cells that are not aligned with the <th>
that come from the parent and they do not have cell borders at all. It's also giving these warnings:
Warning: validateDOMNesting(...): <div> cannot appear as a child of <tbody>. See Param > tbody > Row > div. Warning: validateDOMNesting(...): <tr> cannot appear as a child of <div>. See Row > div > tr. Warning: validateDOMNesting(...): <tr> cannot appear as a child of <div>. See CategoryData > div > tr.
I'm not sure why this warnings are happening and why the table cells(from CategoryData
) are not getting aligned and don't have cell borders. What's the correct way to do it ?
Code
var Param = React.createClass({ getInitialState: function() { return { isLoading: true, panelTitle: "", data: [], categories: [] } }, updateState: function() { var that = this; var categories = new Set(); rest.getParameters('service').then(function (results) { for (var i = 0; i < results.data.length; i++) { categories.add(results.data[i].category); } that.setState({ data: results.data, categories: Array.from(categories) }) }).catch(function (err) { console.error('rest.getParameters(): ', err); that.setState({ isLoading: true, data: [], categories: [] }) }); }, componentDidMount: function() { this.updateState(); }, render: function() { return ( <Panel className="panel-info" header={<h4 className="panel-title">Service Config</h4>}> <div> <table className="table table-striped table-bordered table-hover table-condensed table-responsive"> <thead> <tr> <th className="col-lg-2 text-center">AMP Name</th> <th className="col-lg-2 text-center">Athena Name</th> <th className="col-lg-2 text-center">Description</th> <th className="col-lg-1 text-center">Default</th> <th className="col-lg-1 text-center">Min Value</th> <th className="col-lg-1 text-center">Max Value</th> <th className="col-lg-1 text-center">Action</th> </tr> </thead> <tbody> {this.state.categories.map((category, index) => <th colSpan="7" key={index} style={{'textAlign':'left', 'paddingLeft':'5px', 'backgroundColor': '#D3D0CF'}}>{this.state.category}</th> this.state.data.map((row, i) => if (row.category === category) { <tr key={i}> <td className="col-lg-2 text-center">{row.name}</td> <td className="col-lg-2 text-center">{row.alias}</td> <td className="col-lg-2 text-center">{row.description}</td> <td className="col-lg-1 text-center">{row.default_value}</td> <td className="col-lg-1 text-center">{row.min_value}</td> <td className="col-lg-1 text-center">{row.max_value}</td> <td className="col-lg-1 text-center">Action</td> </tr> } ) )} </tbody> </table> </div> </Panel> ); } });