本文介绍了如何使用行分组对PrimeNG DataTable中的数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做的是对已经按字母顺序或自定义顺序分组的数据进行排序.我使用了sortField属性,它指定了组标题的顺序,但是我也需要对组内的数据进行排序.
What I want to do is to sort the data already grouped in alphabetical order or custom order. I used the sortField attribute wich specify the groupheader order but I need to order the data inside the group too.
推荐答案
我遇到了同样的问题.我添加了自定义排序来解决此问题
I have the same issues. I have added customized sort to solve this issues
添加自定义排序
<p-column field="color" header="color" sortable="custom" (sortFunction)="sortByColor($event)"></p-column>在打字稿中创建一个customSort
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 }); }更多推荐
如何使用行分组对PrimeNG DataTable中的数据进行排序
发布评论