[英]How do I group my list by an attribute which can be null in SAP UI5?
我试图对来自称为服务的实体的项目列表进行分组。 我想通过属性group1_ID对它们进行分组。 问题是某些服务不属于某个组,在这种情况下,group1_ID的值为Null。
我用生成的模拟数据运行了它,其中每个服务的值都为group1_ID的值!== Null。 在这种情况下,按照我的原始尝试,效果很好。
我最初写的是这样的:
<List id="_phaseOverviewList"
items="{
path:'/Services',
sorter: {path: 'group1_ID', group: true}}">
<StandardListItem id="_IDEGen_standardlistitem0" title="{name}"/>
</List>
我也考虑过尝试在Controller.js中对该视图进行排序。 我想这将朝以下方向发展,但我不确定,也不确定如何实现。
oList.getBinding(„items“).sort(new sap.ui.model.Sorter(„group_ID“, false, true));
我曾希望可以根据group1_ID属性对服务进行分组,并希望将group1_ID为空值的服务在列表中分组在一起。 但是,它仅显示未排序/未分组的列表。
在此先感谢您的帮助。
根据规范 ,您应该执行的操作应该在空值结尾。 您可以提供一个返回每个元素的组的函数,而不必说group: true
。 像这样:
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 }}}}"
看看https://gist.github.com/ikiw/bb2de7cd162bd88adf88以及工作示例。 https://blogs.sap.com/2013/11/29/custom-sorter-and-grouper/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.