How to sort data in a PrimeNG DataTable with Row Grouping

前端 未结 3 762
滥情空心
滥情空心 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:31

    For those who have the problem with TurboTable , here is the solution:

    
    

    OnSort() implementation:

    onSort() {
       // function to properly work with turbotable and rowgroup, see: https://www.primefaces.org/primeng/#/table/rowgroup 
       this.updateRowGroupMetaData();
    }
    

    customSort() implementation:

    customSort(e) {
      this.budgets.sort((a, b) => {
        const aGroup = a.name.toLowerCase();
        const bGroup = b.name.toLowerCase();
        if (aGroup > bGroup) { return 1; }
        if (aGroup < bGroup) { return -1; }
        const aSort = a.color;
        const bSort = b.color;
        if (aSort > bSort) { return 1; }
        if (aSort < bSort) { return -1; }
        return 0;
      });
    }
    

提交回复
热议问题