+ Start a Discussion
Sumesh ChandranSumesh Chandran 

Trackable array sorting in Lightning web components

Working on the new Salesforce Lightning web components. I am trying to get the multidimensional array sorted in javascript. I have a trackable array, it has a few columns, i want the data sorted by the total buildings value. Here is what I have done so far, no errors, but not getting the expected results.
@track bc = [];
@wire(getCityStats) cityStats({ data }) {
    if (data) {
      for (let i = 0; i < data.length; i++) {
        if (data[i].sumchans__Province_Code__c == 'BC') {
          this.bc.push(data[i]);
        }
      }
      sortCityByNumberOfBldgs(this.bc);
}
}
  sortCityByNumberOfBldgs(province) {
    province.sort(function(a,b) {
      return a[4]-b[4]
    });
  }

Here is the SOQL in the Apex controller:
SELECT Name,sumchans__Province_Code__c,
        (select sumchans__Penetration__c,sumchans__Total_Buildings__c from sumchans__City_Stats__r) FROM sumchans__CITY_MASTER__c
This is how the data gets displayed when I run the above query and this is the data that is getting stored in the trackable bc array above.
User-added image
 
Gaumuk SinghGaumuk Singh
Thanks author for beautiful posts
mod apk download (https://cloneapk.com/) Funimate pro mod apkfunimate mod apk (https://cloneapk.com/funimate-pro-mod-apk/)
Gaumuk SinghGaumuk Singh
avee player mod apk (https://cloneapk.com/avee-player-pro-mod-apk/)    roblox mod apk (https://cloneapk.com/roblox-mod-apk/)   township mod apk download free (https://cloneapk.com/township-mod-apk/)   mini militia ghost mod (https://cloneapk.com/mini-militia-mod-apk/)  castle crush mod apk (https://cloneapk.com/castle-crush-mod-apk/)  lords mobile mod download free (https://cloneapk.com/lords-mobile-mod-apk/)  
Suraj Singh 60Suraj Singh 60
Thanks for taking the time to share with us such a great article. I really appreciate your work.

https://hindimetro.com/

https://hindigeek.com/

https://mysticmessengeremailguide.com/

https://lyricscentre.com/