Created
May 24, 2014 07:25
React Table Component for creating a very basic html table
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 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
Nice! Thank you.
Just a quick note about Line#35:
renderComponent
has been deprecated. You should use therender
function instead.