Last active
August 29, 2015 14:17
-
-
Save dwinston/441845fd55af3a49331e to your computer and use it in GitHub Desktop.
Use of DataTable via React props for column and row data (stateless)
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
var TabularData = React.createClass({ | |
componentDidMount: function () { | |
$(this.refs.table.getDOMNode()).DataTable(); | |
}, | |
componentDidUpdate: this.componentDidMount, | |
render: function () { | |
var headers = _.pluck(this.props.table.columns, 'title') | |
.map(function (title) { | |
return D.th({key: title}, title); | |
}); | |
var rows = this.props.table.rows | |
.map(function (row) { | |
return D.tr({key: _.uniqueId()}, row.map(function (datum) { | |
return D.td({key: _.uniqueId()}, datum); | |
})); | |
}); | |
return D.table({ref: 'table'}, | |
D.thead({}, D.tr({}, headers)), | |
D.tbody({}, rows)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment