在两个sap.m.Table列上应用sap.ui.model.Filter

时间:2017-08-01 08:29:25

标签: sapui5

两列firstNamelastName。 如何使用绑定的filter方法,以便来自人员输入John Doe的搜索字段中的查询将记录保存在firstName + " " + {的串联中{1}}匹配?

注意:我是在客户端操作模式下执行此操作,因此请不要使用后端过滤解决方案。

1 个答案:

答案 0 :(得分:2)

正确的解决方案是使用自定义过滤器,如:@Andrii。

因此,我们可以创建一个自定义过滤器,该过滤器将根据返回的布尔值运行表中的每一行 自定义过滤器在屏幕上的一行是rendererd。过滤API:Filter

所以,下面是正在运行的代码:

handleSearch: function(e) {
    var sQuery = e.getParameter('query'); // Fecth search term
    var oCustomFilter = new sap.ui.model.Filter({
        path:"", // this refers to binding path of each row.
        test: function(oNode) {
            var oValue = oNode.fname + " " +oNode.lname;
            if (oValue.indexOf(sQuery) !== -1) {
                return true; // row will be rendererd
            } else {
                return false; // row will not be rendererd
            }

        }
    });
    var oBinding = this._table.getBinding('items');
    oBinding.filter(oCustomFilter);
}

表:

            <Table
                id='idTable'
                items= "{/}"
            >
                <columns>
                    <Column
                        headerText='FName'
                    />
                    <Column
                        headerText='LName'
                    />  
                </columns>
                <items>
                    <ColumnListItem>
                        <cells>
                            <Text
                                text='{fname}'
                            />
                            <Text
                                text='{lname}'
                            />
                        </cells>
                    </ColumnListItem>
                </items>
            </Table>

如果您需要任何其他信息,请与我们联系。 :)