/** * File: table.js * Author: Markus Grigull * Date: 02.03.2017 * Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. * Unauthorized copying of this file, via any medium is strictly prohibited. **********************************************************************************/ import React, { Component } from 'react'; import { Table, Button, Glyphicon } from 'react-bootstrap'; import { Link } from 'react-router'; import TableColumn from './table-column'; class CustomTable extends Component { static defaultProps = { width: null }; render() { // create sorted data for rows var rows = []; if (this.props.data) { rows = this.props.data.map((row, index) => { var array = []; for (var i = 0; i < this.props.children.length; i++) { // only handle table-column children if (this.props.children[i].type === TableColumn) { // add content to cell var cell = []; // add data to cell const dataKey = this.props.children[i].props.dataKey; if (dataKey && row[dataKey] != null) { // get content var content; const modifier = this.props.children[i].props.modifier; if (modifier) { content = modifier(row[dataKey]); } else { content = row[dataKey].toString(); } // check if cell should be a link const linkKey = this.props.children[i].props.linkKey; if (linkKey && row[linkKey] != null) { cell.push({content}); } else { cell.push(content); } } // add buttons if (this.props.children[i].props.editButton) { const onEdit = this.props.children[i].props.onEdit; cell.push(); } if (this.props.children[i].props.deleteButton) { const onDelete = this.props.children[i].props.onDelete; cell.push(); } array.push(cell); } } return array; }); } return ( {this.props.children} {rows.map((row, index) => ( {row.map((cell, index) => ( ))} ))}
{cell.map((element, index) => ( {element} ))}
); } } export default CustomTable;