+ Start a Discussion
Sumesh ChandranSumesh Chandran 

Sorting a trackable array in Lightning js

User-added imageThe data attached above is stored in a trackable array in lightning js. I am trying to sort the data by desc using the sumchans__Total_Buildings__c value.
 Here is the function that receives the trackable array and does the sorting, but it doesn't work.
The console log logs the right value, that works.
Please advise!
sortCityByNumberOfBldgs(province) {
console.log(JSON.stringify(this.ab[1].sumchans__City_Stats__r[0].sumchans__Total_Buildings__c));
    theData = JSON.stringify(province);
    theData.sort(function (a, b) {
      return ((a.sumchans__City_Stats__r[0].sumchans__Total_Buildings__c) - (b.sumchans__City_Stats__r[0].sumchans__Total_Buildings__c)) ? 1 : 0;
    })
    this.ab = theData;
  }