Last active
June 28, 2017 17:18
-
-
Save ripitrust/058dd8aca1645daa830b743848ace620 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Table data={servers} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Table extends Component { | |
static PropTypes = { | |
data: React.PropTypes.array.required, | |
}; | |
constructor(props) { | |
super(props); | |
this._renderCell = :: this._renderCell; | |
this._getKeyArray = :: this._getKeyArray; | |
this._getHeaderTitleArray = :: this._getHeaderTitleArray; | |
} | |
_getKeyArray(data){ | |
return Object.keys(data[0] || {}); | |
} | |
_renderCell(keys) { | |
const {data} = this.props; | |
return function(rowIndex, columnIndex) { | |
const key = keys[columnIndex]; | |
const content = data[rowIndex] ? data[rowIndex][key] : null; | |
return <Cell> | |
{content} | |
</Cell> | |
} | |
} | |
render(){ | |
const { _renderCell } = this; | |
const { data, tableHeight } = this.props; | |
const numOfServers = data.length; | |
const keys = this._getKeyArray(data); | |
return ( | |
<div style={{height:tableHeight}}> | |
<Table numRows={numOfServers} | |
style={{height:tableHeight}} | |
defaultColumnWidth={100}> | |
{ keys.map( function(key, index) { | |
return <Column name={key} key={index} renderCell={_renderCell(keys)}/> | |
})} | |
</Table> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment