[英]How do I group my list by an attribute which can be null in SAP UI5?
Im trying to group a list of items from an entity called Services. 我试图对来自称为服务的实体的项目列表进行分组。 I want to group them by the attribute group1_ID.
我想通过属性group1_ID对它们进行分组。 The problem is that some Services dont belong to a group, in which case the value for group1_ID is Null.
问题是某些服务不属于某个组,在这种情况下,group1_ID的值为Null。
Ive run it with generated mock data where every Service had values !== Null for group1_ID. 我用生成的模拟数据运行了它,其中每个服务的值都为group1_ID的值!== Null。 In this case it worked fine with my original attempt.
在这种情况下,按照我的原始尝试,效果很好。
What I had originally written was this: 我最初写的是这样的:
<List id="_phaseOverviewList"
items="{
path:'/Services',
sorter: {path: 'group1_ID', group: true}}">
<StandardListItem id="_IDEGen_standardlistitem0" title="{name}"/>
</List>
I've also considered trying to sort it in the Controller.js for that View. 我也考虑过尝试在Controller.js中对该视图进行排序。 I guess that would go in the direction of the following, but I'm not sure and I'm not sure how I should implement that.
我想这将朝以下方向发展,但我不确定,也不确定如何实现。
oList.getBinding(„items“).sort(new sap.ui.model.Sorter(„group_ID“, false, true));
I had hoped that the Services would be grouped based on the group1_ID attribute, and that Services with a Null value for group1_ID would be grouped together in the list. 我曾希望可以根据group1_ID属性对服务进行分组,并希望将group1_ID为空值的服务在列表中分组在一起。 However, it just displays the list, unsorted/ungrouped.
但是,它仅显示未排序/未分组的列表。
Thanks in advance for your help. 在此先感谢您的帮助。
From the specs what you do should already work, the null values should come at end. 根据规范 ,您应该执行的操作应该在空值结尾。 Instead of saying
group: true
you can provide a function that returns the group for each element. 您可以提供一个返回每个元素的组的函数,而不必说
group: true
。 Something like this: 像这样:
items="{
path:'/Services',
sorter: {path: 'group1_ID', group: function(oContext){
let x = oContext.getProperty('group1_ID') || ''; //defaults to an empty string
return { key: x, title : x }}}}"
Have a look at https://gist.github.com/ikiw/bb2de7cd162bd88adf88 and for working examples. 看看https://gist.github.com/ikiw/bb2de7cd162bd88adf88以及工作示例。 https://blogs.sap.com/2013/11/29/custom-sorter-and-grouper/
https://blogs.sap.com/2013/11/29/custom-sorter-and-grouper/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.