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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -