Skip to Content
0
Dec 12, 2020 at 12:55 PM

Cannot filter table in UI5

399 Views

Hello everyone.

I tried to apply filter to a table in SAP UI5 coding.

But it doesn't work.

List.view.xml

<mvc:View
    xmlns:mvc="sap.ui.core.mvc"
    xmlns="sap.m"
    xmlns:core="sap.ui.core"
    controllerName="sap.cp.webapp.controller.List" 
    displayBlock="true">
    <Page
        id="listPage"
        title="Sales Order List">
    <content>
        <Toolbar>
            <Title width="100%" text="Filter"/>
                <SearchField  search=".onCompanyName"/>                                        
        </Toolbar>
        <Table
            id="table0"
            items="{path:'/SalesOrderSet',sorter:[{path:'SalesOrderID',descending:false}]}"
            >
            <columns>
Omission
            </columns>
            <items>
                <ColumnListItem
                    type="Active"
                    id="item0"
                    press="handleListItemPress">
                    <cells>
                        <Text
                            text="{SalesOrderID}"/>
                        <ObjectIdentifier
                            title="{CustomerName}"
                            text="{CustomerID}"/>
Omission
                    </cells>
                </ColumnListItem>
            </items>
            </Table>
    </content>
    </Page>
</mvc:View>

List.controller.js

sap.ui.define([
    "sap/ui/core/mvc/Controller",    
    'sap/ui/model/Filter',
    "sap/ui/model/FilterOperator"
],
    function (Controller, Filter, FilterOperator) {
        "use strict";
        return Controller.extend("sap.cp.webapp.controller.List", {
            onCompanyName : function (oEvent) {
                var oTable = this.byId("table0");
                var sQuery = oEvent.getParameter("query");
                var oFilter;
                oFilter = new sap.ui.model.Filter("CompanyName", "EQ", sQuery); 
                oTable.getBinding("rows").filter([oFilter]);
            }
        });
    });

On debugging screen, following error is shown.

`Uncaught TypeError: Cannot read property 'filter' of undefined`

Could you possible tell me how to solve this problem, please?

Attachments

yzw1t.png (127.4 kB)