Skip to content

Instantly share code, notes, and snippets.

@icaromh
Forked from ChaseWest/react-table-component.js
Last active August 29, 2015 14:13
Show Gist options
  • Save icaromh/223b4d6ef53d0c4d97eb to your computer and use it in GitHub Desktop.
Save icaromh/223b4d6ef53d0c4d97eb to your computer and use it in GitHub Desktop.
var Table = React.createClass({
render: function render() {
var _self = this;
var thead = React.DOM.thead({},
React.DOM.tr({},
this.props.cols.map(function (col) {
return React.DOM.th({}, col);
})));
var tbody = this.props.rows.map(function (row) {
return React.DOM.tr({},
_self.props.cols.map(function (col) {
return React.DOM.td({}, row[col] || "");
}));
});
return React.DOM.table({}, [thead, tbody]);
}
});
var container = document.querySelector("#container");
var tableModel = {
cols: ["Name", "Age"],
rows: [{
"Name": "Chase",
"Age": "27"
}],
}
React.renderComponent(Table(tableModel), container);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment