在自定义智能筛选字段中保存值

Saving values in custom smart filter field

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

.. 使用自定义字段。它是这样定义的:

<smartFilterBar:ControlConfiguration
    key="MyOwnFilterField" index="1" label="Custom Filter Field"
    groupId="_BASIC" width="300px" mandatory="mandatory"
    visibleInAdvancedArea="true">

    <smartFilterBar:customControl>
      <m:Select id="foo" customData:hasValue="true">
        <core:Item key="1" text="ONE"/>
        <core:Item key="2" text="TWO"/>
        <core:Item key="3" text="THREE"/>
      </m:Select>
    </smartFilterBar:customControl>

</smartFilterBar:ControlConfiguration>

保存变体时,所有字段的值和selected 键都会被保存,自定义字段中的值除外

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

由于我将自定义控件的选定键和值保存在 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);
  },

... 这又允许我在智能 table.

上的 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));
  }
});