如何使用行分组对PrimeNG DataTable中的数据进行排序

编程入门 行业动态 更新时间:2024-10-27 03:29:46
本文介绍了如何使用行分组对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中的数据进行排序

本文发布于:2023-11-25 16:30:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630498.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   数据   PrimeNG   DataTable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!