sortBy()

in services/self-service/src/main/resources/webapp/src/app/reports/reporting/reporting-grid/reporting-grid.component.ts [142:174]


  sortBy(sortItem, direction) {
    if (this.previousItem === sortItem && this.previousDirection === direction) return;

    let report: Array<object>;
    this.previousItem = sortItem;
    this.previousDirection = direction;

    if (direction === 'down') {
      report = this.reportData.sort((a, b) => {
        if (a[sortItem] === null) a[sortItem] = '';
        if (b[sortItem] === null) b[sortItem] = '';

        if ((a[sortItem] > b[sortItem])) return 1;
        if ((a[sortItem] < b[sortItem])) return -1;
        return 0;
      });
    }

    if (direction === 'up') {
      report = this.reportData.sort((a, b) => {
        if (a[sortItem] === null) a[sortItem] = '';
        if (b[sortItem] === null) b[sortItem] = '';

        if ((a[sortItem] < b[sortItem])) return 1;
        if ((a[sortItem] > b[sortItem])) return -1;
        return 0;
      });
    }

    this.refreshData(this.fullReport, report);
    this.removeSorting();
    this.active[sortItem + direction] = true;
  }