How do I sort data within a table by when it was last updated?


#1

On my application, a user can add data and it will appear in a table. They can then edit this data, I would like to make it so the data that is edited will move to the top of the table. Please could I get some help? I tried sortBy but wasn’t sure how to do it properly.

Controller

    var client = this.get('clientName');
    var number = this.get('clientNumber');
    var lastUpdated = moment(new Date());
    
    var createClient = this.store.createRecord('clientdetails', {
        client: client,
        number: number,
        lastUpdated: lastUpdated
    } createClient.save();

Template

{{each client in clientdetails}}
<tr>
   <td>{{client.client}}</td>
   <td>{{client.number}}</td>
</tr

Thank you!!


#2

Here’s an idea that may help you head in the right direction–

createClient.save().then(onSuccess);

var onSuccess = function(client) {
  //append row using js function insertRow(0) or use jquery 
  //delete row using js function deleteRow(current position) or jquery
};