如何按 SAP UI5 中可以为空的属性对列表进行分组?
How do I group my list by an attribute which can be null in SAP UI5?
我正在尝试对来自名为“服务”的实体的项目列表进行分组。我想按属性 group1_ID 对它们进行分组。问题是某些服务不属于某个组,在这种情况下 group1_ID 的值为 Null。
我已经 运行 它生成了模拟数据,其中每个服务的值都为 !== Null group1_ID。在这种情况下,我最初的尝试效果很好。
我原来写的是这样的:
<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 空值的服务会在列表中组合在一起。但是,它只显示列表 unsorted/ungrouped.
在此先感谢您的帮助。
从 the specs 开始,您所做的应该已经起作用,空值应该在最后。不用说 group: true
你可以提供一个函数 returns 每个元素的组。像这样:
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 and for working examples. https://blogs.sap.com/2013/11/29/custom-sorter-and-grouper/
我正在尝试对来自名为“服务”的实体的项目列表进行分组。我想按属性 group1_ID 对它们进行分组。问题是某些服务不属于某个组,在这种情况下 group1_ID 的值为 Null。
我已经 运行 它生成了模拟数据,其中每个服务的值都为 !== Null group1_ID。在这种情况下,我最初的尝试效果很好。
我原来写的是这样的:
<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 空值的服务会在列表中组合在一起。但是,它只显示列表 unsorted/ungrouped.
在此先感谢您的帮助。
从 the specs 开始,您所做的应该已经起作用,空值应该在最后。不用说 group: true
你可以提供一个函数 returns 每个元素的组。像这样:
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 and for working examples. https://blogs.sap.com/2013/11/29/custom-sorter-and-grouper/