mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Fix props loading in table component
This commit is contained in:
parent
4964a5f79f
commit
ce1972dd45
1 changed files with 26 additions and 26 deletions
|
@ -24,15 +24,14 @@ import _ from 'lodash';
|
|||
import { Table, Button, Glyphicon, FormControl, Label, Checkbox } from 'react-bootstrap';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
//import TableColumn from './table-column';
|
||||
|
||||
class CustomTable extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.activeInput = null;
|
||||
|
||||
this.state = {
|
||||
rows: [],
|
||||
rows: this.getRows(props),
|
||||
editCell: [ -1, -1 ]
|
||||
};
|
||||
}
|
||||
|
@ -119,30 +118,9 @@ class CustomTable extends Component {
|
|||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
// check if data exists
|
||||
if (nextProps.data == null) {
|
||||
this.setState({ rows: [] });
|
||||
return;
|
||||
}
|
||||
const rows = this.getRows(nextProps);
|
||||
|
||||
// create row data
|
||||
var rows = nextProps.data.map((data, index) => {
|
||||
// check if multiple columns
|
||||
if (Array.isArray(nextProps.children)) {
|
||||
var row = [];
|
||||
|
||||
nextProps.children.forEach(child => {
|
||||
row.push(this.addCell(data, index, child));
|
||||
});
|
||||
|
||||
return row;
|
||||
} else {
|
||||
// table only has a single column
|
||||
return [ this.addCell(data, index, nextProps.children) ];
|
||||
}
|
||||
});
|
||||
|
||||
this.setState({ rows: rows });
|
||||
this.setState({ rows });
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
|
@ -162,6 +140,28 @@ class CustomTable extends Component {
|
|||
this.setState({ editCell: [ -1, -1 ] });
|
||||
}
|
||||
|
||||
getRows(props) {
|
||||
if (props.data == null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return props.data.map((data, index) => {
|
||||
// check if multiple columns
|
||||
if (Array.isArray(props.children) === false) {
|
||||
// table only has a single column
|
||||
return [ this.addCell(data, index, props.children) ];
|
||||
}
|
||||
|
||||
const row = [];
|
||||
|
||||
for (let child of props.children) {
|
||||
row.push(this.addCell(data, index, child));
|
||||
}
|
||||
|
||||
return row;
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
// get children
|
||||
let children = this.props.children;
|
||||
|
|
Loading…
Add table
Reference in a new issue