Created
February 16, 2015 23:27
-
-
Save pauldambra/cc364759476076779bcd to your computer and use it in GitHub Desktop.
Sorting some data with ReactJS
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 PayTable = React.createClass({ | |
getInitialState: function() { | |
return { | |
sortDirection: 'descending', | |
data: this.props.payYears.sort(sortDescending) | |
}; | |
}, | |
sortData: function() { | |
if(this.state.sortDirection==='descending') { | |
this.setState({ | |
sortDirection: 'ascending', | |
data: this.props.payYears.sort(sortAscending) | |
}); | |
} else { | |
this.setState({ | |
sortDirection: 'descending', | |
data: this.props.payYears.sort(sortDescending) | |
}); | |
} | |
}, | |
render: function() { | |
return ( | |
<table className="table table-striped"> | |
<thead> | |
<tr> | |
<th onClick={this.sortData} | |
className={this.state.sortDirection}> | |
Year | |
</th> | |
<th>All</th> | |
<th>Full-time</th> | |
<th>Part-time</th> | |
</tr> | |
</thead> | |
<tbody> | |
{this.state.data.map(function(payYear) { | |
return <PayRow key={payYear.year} payYear={payYear} />; | |
})} | |
</tbody> | |
</table> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment