How to sort data in a PrimeNG DataTable with Row Grouping

前端 未结 3 695
滥情空心
滥情空心 2021-02-10 21:30

What I want to do is to sort the data already grouped in alphabetical order or custom order. I used the sortField attribute which specify the groupheader order but

3条回答
  •  广开言路
    2021-02-10 22:23

    I have the same issues. I have added customized sort to solve this issues

    To add a customized sort

    
    

    In the typescript create a customSort

    sortByColor(e) {
        this.cars.sort(function (a, b) {
          let aGroup = a.name.toLowerCase();
          let bGroup = b.name.toLowerCase();
          if (aGroup > bGroup) return 1;
          if (aGroup < bGroup) return -1;
          let aSort = a.color.toLowerCase();
          let bSort = b.color.toLowerCase();
          if (aSort > bSort) return 1;
          if (aSort < bSort) return -1;
          return 0
        });
      }
    

提交回复
热议问题