FilterBar中的BasicSearch不起作用

时间:2018-08-03 09:25:11

标签: sapui5

我声明一个搜索字段并将其添加到过滤器栏。该代码不起作用,但在控制台中也不返回任何内容。

谁能告诉我这是什么问题,为什么它不起作用?

此致

Binh

这是搜索字段

if (oFilterBar.setBasicSearch) {
  oFilterBar.setBasicSearch(new sap.m.SearchField({
    showSearchButton: sap.ui.Device.system.phone,
    placeholder: "Search",
    liveChange: function() {
      oValueHelpDialog.getFilterBar().search();  
  }));
}

oValueHelpDialog.setFilterBar(oFilterBar);

然后将其添加到此过滤器栏

var oFilterBar = new sap.ui.comp.filterbar.FilterBar({
  ...
  filterGroupItems: [
    new sap.ui.comp.filterbar.FilterGroupItem({
      groupTitle: "foo",
      groupName: "gn1",
      name: "n1",
      label: "Supplier ID",
      control: new sap.m.Input()
    }),
    new sap.ui.comp.filterbar.FilterGroupItem({
      groupTitle: "foo",
      groupName: "gn1",
      name: "n2",
      label: "Company Name",
      control: new sap.m.Input()
    })
  ],
  search: function(oEvent) {
    var oSource = oEvent.getSource();
    var oBarContent = oSource.getContent();
    var oToolBarContent = oBarContent[0].getContent();
    var oSearch = oToolBarContent[1];
    var sQuery = oSearch.getValue();

    return [
      new sap.ui.model.Filter(
        "Supplier ID",
        sap.ui.model.FilterOperator.Contains,
        sQuery
      ),
      new sap.ui.model.Filter(
        "Company Name",
        sap.ui.model.FilterOperator.Contains,
        sQuery
      )
    ];
  }
});

1 个答案:

答案 0 :(得分:0)

我发现我不必打oValueHelpDialog.getFilterBar().search();。可以毫无问题地将其删除。

相反,我将所有内容都放在了if子句中

if (oFilterBar.setBasicSearch) {
  oFilterBar.setBasicSearch(new sap.m.SearchField({
    showSearchButton: sap.ui.Device.system.phone,
    placeholder: "Search",
    search: function(oEvent) {
      var oBinding = oValueHelpDialog.getTable().getBinding("items");
      var sQuery = oEvent.getParameter("query");
      var aFilter1 = [
        new sap.ui.model.Filter("SupplierID", sap.ui.model.FilterOperator.EQ, sQuery),
        new sap.ui.model.Filter("CompanyName", sap.ui.model.FilterOperator.Contains, sQuery)
      ];
      var allFilter = new sap.ui.model.Filter(aFilter1 , false);
      oBinding.filter(allFilter);
    }
  }));
}

oValueHelpDialog.setFilterBar(oFilterBar);