Skip to Content
avatar image
Former Member

Bind data to table using filter

tab.bindItems("/OrdItabSet", tab, null, oFilters);

I am developing a table and while binding data to it in need to apply filter my code is as below

XML code

<Table id="idProductsTable"  rows="{/OrdItabSet}" >

                <columns>

                    <Column>

                        <Label text="Employee Number" />

                    </Column>

                    <Column>

                        <Label text="Employee Name" />

                    </Column>

                    <Column>

                        <Label text="Default Password" />

                    </Column>

                </columns>

                <items>

                        <Input value ="{OrdItab/Order}"></Input>

                        <Input value="{OrdItab/Order}"></Input>

                        <Input value="{OrdItab/Order}"></Input>

                   

                    </ColumnListItem>

                </items>

            </Table>

JS code

var tab = this.getView().byId("idProductsTable");

var oFilters = [ new sap.ui.model.Filter("CustId","EQ", "'"+custId+"'") ];

tab.bindItems("/OrdItabSet", tab, null, oFilters);

But its showing no data.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 23, 2015 at 07:19 AM

    If you are trying to use a sap.ui.table you can try the following:

    <Table id="idProductsTable"  rows="{/OrdItabSet}" >

                    <columns>

                        <Column>

                            <Label text="Employee Number" />

                        <template>

                             <Label text={rowPropertyEmployeeNumber} />

                        </template>

                        </Column>

                        <Column>

                            <Label text="Employee Name" />

                        <template>

                             <Label text={rowPropertyEmployeeName} />

                        </template>

                        </Column>

                        <Column>

                            <Label text="Default Password" />

                        <template>

                             <Label text={rowPropertyDefaultPassword} />

                        </template>

                        </Column>

                    </columns>

      </Table>

    With this you should get at least a normal table to work. Now for the filter side of things:

    var tab = this.getView().byId("idProductsTable");

    var oBinding = table.getBinding("rows");

    var oFilters = [ new sap.ui.model.Filter("CustId",sap.ui.model.FilterOperator.EQ, "'"+custId+"'") ];

    oBinding.filter(oFilters);


    This should apply the filters to the binding. Notice that i have used a constant provided by the ui5 library called sap.ui.model.FilterOperator.EQ. If you want to remove the filter simply put an empty array to the binding. Now it's up to you to implement this and tell us if everything works well.


    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Well that's only one tiny piece....

      I don't know your data source...can you give us an example of the table or the service definition?

      Can you show us what you have now as your source code?

      You should really provide more information and not only 1 sentence...

  • Oct 23, 2015 at 06:59 AM

    Sham,


    Which library does the table control belongs to? Since, your code says in XML view as rows="{}" and in the JS code as .bindItems() ? For table commons, there are rows and mobile table there are items.


    And one more thing, custId value is user input / is it dynamic?


    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Sai Vellanki

      Hi sai,

      thanks. But now problem is that i am passing items like this

      <Table id="idProductsTable" items="{/OrdItabSet}">

      and application is only keep loading not showing any screen.

      Beacuse wen m runnig /sap/opu/odata/SAP/ZCUST_FABT_SHEET_SRV/OrdItabSet in segw without filter its not showing anything with filter its showing output in segw.

  • Oct 23, 2015 at 07:02 AM

    Hi Sham,

    .bindItem("/items", oItem, null, [oFilter2]) is not supported in OpenUI5. Ref: https://github.com/SAP/openui5/issues/130

    Check weather you are using openUI5.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 23, 2015 at 07:51 AM

    Hi Sham,

    Check this sample: JS Bin - Collaborative JavaScript Debugging

    Provide weight value which exists in the table for the input which is placed at the bottom. For example provide input value as 103 it will filter the item with weight as 103.


    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded