cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot filter table in UI5

koichiro_ogawa01
Participant
0 Kudos

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?

Accepted Solutions (0)

Answers (3)

Answers (3)

maheshpalavalli
Active Contributor

Its getBinding("items"), not rows, as items is for m.table and rows is for ui.table.

koichiro_ogawa01
Participant
0 Kudos

Dear maheshkumar.palavalli

Thank you for your comment!

I'll try to fix depending your hint.

maheshpalavalli
Active Contributor
0 Kudos
koichiro.ogawa01, Welcome!! this should surely fix it, let us know 🙂
koichiro_ogawa01
Participant
0 Kudos

Dear maheshkumar.palavalli

Thank you for your kindness.

I fixed the code and actually the error seems to occur no longer.

However the filtered table doesn't appear on view.

No record is displayed.

  • Before filtering

  • After Filtering

Could you tell me how to apply the filtered table on the View, please?

Here is my source.

https://github.com/Auggie9010/fiori_salesorder_list2

Sincerely

Koichiro

koichiro_ogawa01
Participant
0 Kudos

Dear jun.wu5

Dear maheshkumar.palavalli

After I change it from "CompanyName" to "CustomerName", it works.

I appreciate you and please forgive this easy mistake.

Let me close this question.

Sincerely

Koichiro

junwu
Active Contributor
0 Kudos

your column name is CustomerName, not CompanyName, which is used in your filter.