简体   繁体   中英

openui5 list bound to a model with different list item types

I have a sap.m.List in openui5 which is bound to a JSON model.

The list should contain normal list items (such as the type sap.m.StandardListItem), but there should also be separator once every year through the list item type sap.m.GroupHeaderListItem. Example JSBin with such a list

Is it possible to achieve this when the data is bound using bindAggregation?

Yes, should be perfectly possible, have a look at the example at https://sapui5.hana.ondemand.com/sdk/explored.html#/sample/sap.m.sample.ListGrouping/code

Of course you need to sort your aggregation to the field you need to group on, and then you can supply a groupHeaderFactory to your items aggregation:

<List items="{
  path: '/ProductCollection',
  sorter: {
    path: 'SupplierName',
    descending: false,
    group: true
  },
  groupHeaderFactory: '.getGroupHeader'
}">

and the called factory function then returns a GroupHeaderListItem based on a certain value for your data:

getGroupHeader: function (oGroup){
    return new sap.m.GroupHeaderListItem( {
        title: oGroup.key,
        upperCase: false
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM