如何根据表行数据在表下拉列表中设置过滤器 [英] How to set filter in table dropdown based on table row data

查看:100
本文介绍了如何根据表行数据在表下拉列表中设置过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下问题由SCN上的这个SAPUI5主题驱动:)



但是......



由于某种原因,当前当前表的除法属性的值未被识别,或者在创建过滤器时根本未设置(我无法判断哪个是真的),导致第二个下拉列表空(即没有有效的过滤器)。



因此错误在于此值的绑定单行代码:

  filters:[new sap.ui.model.Filter(division,sap.ui.model .FilterOperator.EQ,{tablemodel> division})] 

我的问题是:


  1. 是否有可能在表中以这种方式设置过滤器,即使用数据绑定为每行设置过滤器值,如 {tablemodel> division} ?我知道它在表外工作,但在这种情况下,下拉列表是一个相对绑定到表数据的模板

  2. 如果不可能,我该如何使它工作?我怀疑数据绑定应该隐式工作,但由于某种原因它不会

限制:



理想情况下,我不想在第一个下拉列表中使用 onChange 事件,因为第二个下拉列表应该已经根据可用的表格数据进行过滤,而不是使用第一个下拉菜单进行选择更改。



任何帮助将不胜感激!



========================================== =======



编辑:我刚刚测试了一个只有一个下拉列表的页面,并且它也不起作用! ...



如果我使用的过滤器数据绑定指定过滤器值 value1

  new sap.ui.model.Filter({
path:division,
operator :sap.ui.model.FilterOperator.EQ,
value1:{/ someProperty}
})

然后下拉列表不呈现任何项目



但是,如果我在属性 value1 中对值进行硬编码:

  new sap.ui.model.Filter({
path:division,
operator:sap.ui. model.FilterOperator.EQ,
value1:测试
})

然后过滤器按预期工作。



底线:


是否真的我们不能使用数据绑定来指定过滤器值?



解决方案

true 我们不能使用数据绑定来指定过滤器值。请查看您的另一个问题的答案无法设置过滤器值使用数据绑定?


The following question was driven by this SAPUI5 topic on SCN: 2 dropdownboxs, filtering second off the the value in first

  • We have a SAPUI5 table, containing two columns, each record in the table shows a dropdown: one for Divisions, and one for Business Units.
  • Depending on the value of the selected Division, the Business Unit dropdown should only show the BU's which are valid for the chosen division
  • The actual table data is stored in a named model tablemodel, the data for the dropdowns is stored in a named model metamodel

See below example of how the table should look like:

In order to be able to filter the Business Units on Division, the named model metamodel looks like:

divisions: [
    {
        division    : "div1",
        divisiondesc: "Division 1"
    }, 
    {
        division    : "div2",
        divisiondesc: "Division 2"
    }, //etc
],
bunits: [
    {
        busunit    : "bus1",
        busunitdesc: "Business Unit 1",
        division   : "div1"
    }, 
    {
        busunit    : "bus2",
        busunitdesc: "Business Unit 2",
        division   : "div3"
    }, //etc
]

so the 2nd dropdown (which binds to /bunits) can be filtered on property division.

The sap.ui.commons.table.Table is built in a JSView component as follows:

var oTable = new sap.ui.table.Table()
    //First column w/ dropdown Divisions
    .addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({
            text: "Division"
        }),
        template: new sap.ui.commons.DropdownBox({
            selectedKey: "{tablemodel>division}",
            items: {
                path: "metadatamodel>/divisions",
                template: new sap.ui.core.ListItem({
                    text: "{metadatamodel>divisiondesc}",
                    key: "{metadatamodel>division}"
                })
            }
        })
    }))
    //Second column w/ dropdown Business Units, which should be filtered
    .addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({
            text: "Business Unit"
        }),
        template: new sap.ui.commons.DropdownBox({
            selectedKey: "{tablemodel>bus_unit}",
            items: {
                path: "metadatamodel>/bunits",
                template: new sap.ui.core.ListItem({
                    text: "{metadatamodel>busunitdesc}",
                    key: "{metadatamodel>busunit}"
                })
                ,
                filters: [new sap.ui.model.Filter("division", sap.ui.model.FilterOperator.EQ, "{tablemodel>division}")]
            }
        })
    }))
    .bindRows("tablemodel>/");

As you can see from the above, the intended behavior is that the second dropdown will be filtered on property division with the value of the current table's division property (i.e. {tablemodel>division}).

(The full code is available in this JSbin project )

However...

For some reason the value for the current current table's division property is not being recognized, or is simply not set when the filter is created (I'm not able to tell which is true), resulting in an empty 2nd dropdown (i.e. no valid filter).

The error thus lies in the value binding of this single line of code:

filters: [new sap.ui.model.Filter("division", sap.ui.model.FilterOperator.EQ, "{tablemodel>division}")]

My question is:

  1. Is it possible at all to have a filter setup this way in a table, i.e. setting a filter value for each row using data binding like {tablemodel>division}? I know it works outside a table, but in this case the dropdown is a template with relative binding to the table data
  2. If not possible, how should I get it to work? I would suspect data binding should work implicitly, but for some reason it doesn't

Restrictions:

Ideally, I don't want to use an onChange event for the first dropdown, since the second dropdown should already be filtered based on the available table data, and not a selection-change made with the first dropdown.

Any help will be greatly appreciated!

=================================================

EDIT: I just tested with a page with nothing more than a single dropdown, and there it doesn't work either!...

If I use a filter where the filter value value1 is specified by data binding:

new sap.ui.model.Filter({
    path     : "division", 
    operator : sap.ui.model.FilterOperator.EQ, 
    value1   : "{/someProperty}"
})

then the dropdown does not render any items

However, if I hardcode a value at property value1:

new sap.ui.model.Filter({
    path     : "division", 
    operator : sap.ui.model.FilterOperator.EQ, 
    value1   : "Test"
})

Then the filter works as expected.

Bottomline:

Is it true we can't use data binding for specifying a filter value?

解决方案

it is true we can't use data binding for specifying a filter value. Please see the answer of your another question Not possible to set Filter value using data binding?.

这篇关于如何根据表行数据在表下拉列表中设置过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆