How to sort HTML Table in ReactJS -
i have array
of objects
, add data html table
. need sort data version. how can in react
?
render() { return ( <div> <div> <label> got {this.state.count} elements in our database. </label> </div> <div> <table hover striped bordered responsive size="sm" > <thead> <tr> <th>version</th> <th>date</th> <th>uuid</th> </tr> </thead> <tbody> {this.state.results.map(result => <tr key={result.fileid}> <td>{result.version}</td> <td>{result.origin}</td> <td>{result.uuid}</td> </tr> )} </tbody> </table> </div> </div> ); } }
maybe can use js
script, tell me how use it, i'm new reactjs
. version 0.26.8
example.
i use lodash's sortby()
function here:
https://lodash.com/docs/4.17.4#sortby
const sorted = _.sortby(this.state.results, 'version')
then map on sorted
instead of this.state.results
Comments
Post a Comment