Skip to content

Instantly share code, notes, and snippets.

@dwinston
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwinston/441845fd55af3a49331e to your computer and use it in GitHub Desktop.
Save dwinston/441845fd55af3a49331e to your computer and use it in GitHub Desktop.
Use of DataTable via React props for column and row data (stateless)
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