• Suraj Singh 60
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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