簡體   English   中英

如何按SAP UI5中可以為空的屬性對列表進行分組?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM