将值保存在自定义智能过滤器字段中

时间:2019-01-13 21:55:36

标签: sapui5

在此智能过滤器示例中:https://sapui5.hana.ondemand.com/#/sample/sap.ui.comp.sample.smartfilterbar.example2/preview

..使用一个自定义字段。定义如下:

div.a {
  text-align: justify; /* For Edge */
  -moz-text-align-last: right; /* For Firefox prior 58.0 */
  text-align-last: right;
}

<div class="a">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</p>
</div>

保存变体时,所有字段的值和选定的键都会保存,除了是自定义字段中的值。

我还想将值存储在自定义字段中,在示例中是选择。有办法吗?

1 个答案:

答案 0 :(得分:1)

由于我将自己的自定义控件的选定键和值保存在JSON模型中,因此使用LREP有效负载保存和还原它们相当简单。在过滤器数据上设置_CUSTOM键会填充在过滤器栏本身上设置的JSON模型,称为fi1t3rM0d31

因此,此字段:

<smartFilterBar:ControlConfiguration 
  key="OrderTypeId" 
  index="0" 
  label="{i18n>orders.enquiry.ordertype}" 
  groupId="_BASIC" 
  visibleInAdvancedArea="true" 
  controlType="input">
  <smartFilterBar:customControl>
    <MultiComboBox 
      customData:hasValue="true" 
      selectedKeys='{filters>/filters/multi/OrderTypeId}' 
      items="{
              templateShareable: 'true', path: '/HelpValues',
              filters: [{path:'FieldName', operator:'EQ', value1: 'VBAK-AUART'}]
            }">
      <core:ListItem key="{Key}" text="{Value}"/>
    </MultiComboBox>
  </smartFilterBar:customControl>
</smartFilterBar:ControlConfiguration>

我可以在“过滤器”栏上使用这些事件:

  /**
   * This event on the smart filter bar triggers before a variant is saved 
   * @param  {sap.ui.base.Event} oEvent 
   */
  beforeVariantSave: function(oEvent) {
    oEvent.getSource().setFilterData({_CUSTOM:this.getModel('filters').getProperty('/filters')});
  },

  /**
   * This event on the smart filter bar triggers after a variant is loaded 
   * @param  {sap.ui.base.Event} oEvent 
   */
  afterVariantLoad: function(oEvent) {
    var custom = oEvent.getSource().getFilterData()._CUSTOM;

    this.getModel('filters').setProperty('/filters', custom);
  },

...这又使我能够在智能表上的beforeRebindTable事件中生成类似的过滤器。

//multi keys
Object.keys(data.multi || {}).forEach(k => {
  var f = [];
  data.multi[k].forEach(v => {
    if (v) f.push(new Filter(k, FilterOperator.EQ, v));
  });

  if (f.length > 0) {
    this.aFilters.push(new Filter(f));
  }
});