cancel
Showing results for 
Search instead for 
Did you mean: 

Bind data to table using filter

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

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.


Former Member
0 Kudos

Hi Dirk,

I am using sap.m.table. I am using Items instead of rows.How to bimd it with help of items.Do i have to define filter in my XML code as well.

Former Member
0 Kudos

Hi,

You can use the getBinding() to filter the items as sai suggessted,

var oFilter1 = new sap.ui.model.Filter(
"CustId",
sap.ui.model.FilterOperator.EQ,
<Value of the Cust Id>);

this.getView().byId("idProductsTable").getBinding(
"items").filter([ oFilter1 ]);

Thanks,

Rumeshbabu S

Former Member
0 Kudos

Hi Rumeshbabu,

I understood the code for javascript but now problem is in XML items as i mentioned.Can please you suggest me sumthing on that.

0 Kudos

Somebody explained a sap.m.table already in this thread. Can you try that? Does it solve your problem?

How about this:

  1. <Table items="{/yourData}"
  2.     <columns> 
  3.         <Column> 
  4.             <Label text="LinkColumn" /> 
  5.         </Column> 
  6.         <!-- etc --> 
  7.     </columns> 
  8.     <items> 
  9.         <ColumnListItem> 
  10.             <cells> 
  11.                 <Link text="{user}" press="handleLinkPress"
  12.                     <customData> 
  13.                         <core:CustomData key="step" value="{step}" /> 
  14.                         <core:CustomData key="action" value="{step}" /> 
  15.                     </customData> 
  16.                 </Link> 
  17.                 <!-- etc --> 
  18.             </cells> 
  19.         </ColumnListItem> 
  20.     </items> 
  21. </Table>
Former Member
0 Kudos

Hi dirk,

I tried your code its showing canont read the property "filter" of undefined.

var table = 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);

<Table
rows="{/OrdItabSet}"
title="Products"
selectionMode="MultiToggle"
visibleRowCount="7"
id="idProductsTable">
0 Kudos

Since you have changed the type from sap.ui.table to sap.m.table you (and therefore also the aggregation property) try the following

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

Former Member
0 Kudos

Hi,

Please mention "items" instead "rows" if you are using sap.m.Table.

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

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

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

  oBinding.filter(oFilters);

Regards,

Rumeshbabu S

Former Member
0 Kudos

But i trying it with rows="{/OrdItabSet}" still i have to use rows="{/OrdItabSet}".

0 Kudos

I do not understand. Could you please post once again your whole source code?

Thanks.

Former Member
0 Kudos

Hi,

You should use items="{/OrdItabSet}" instead of rows="{/OrdItabSet}".

Regards,

Rumeshbabu S

Former Member
0 Kudos

sorry for confusion.I will explain it again.now m trying like this but for

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

OBinding its showing is undefined.

my js code is as below

  var table = 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);

and XML code is

<Table

  rows="{OrdItab/OrdItabSet}"

  title="Products"

  selectionMode="MultiToggle"

  visibleRowCount="7"

  id="idProductsTable">

  <columns>

  <Column width="9rem">

  <m:Label text="{OrdItab/Order}" />

  </Column>

  <Column width="9rem">

  <m:Label text="{OrdItab/Orderdt}" />

  </Column>

  <Column width="9rem">

  <m:Label text="{OrdItab/Orderdt}" />

  </Column>

  <Column width="9rem">

  <m:Label text="{OrdItab/Orderdt}" />

  </Column>

  <Column width="9rem">

  <m:Label text="{OrdItab/Orderdt}" />

  </Column>

  <Column width="12rem">

  <m:Label text="{OrdItab/Orderdt}" />

  </Column>

  </columns>

  </Table>

0 Kudos

See highlighted changes

JS Code:

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

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

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

oBinding.filter(oFilters);

XML

<m:Table

  items="{OrdItab/OrdItabSet}"

  title="Products"

  selectionMode="MultiToggle"

  visibleRowCount="7"

  id="idProductsTable">

  <columns>

  <Column width="9rem">

  <m:Label text="{OrdItab/Order}" />

  </Column>

  <Column width="9rem">

  <m:Label text="{OrdItab/Orderdt}" />

  </Column>

  <Column width="9rem">

  <m:Label text="{OrdItab/Orderdt}" />

  </Column>

  <Column width="9rem">

  <m:Label text="{OrdItab/Orderdt}" />

  </Column>

  <Column width="9rem">

  <m:Label text="{OrdItab/Orderdt}" />

  </Column>

  <Column width="12rem">

  <m:Label text="{OrdItab/Orderdt}" />

  </Column>

  </columns>

<items>

   <ColumnListItem>  

     <cells>

                <Link text="{user}" >

                </Link>

                <!-- etc -->

            </cells>

        </ColumnListItem>

    </items>

</m:Table>

You have to add items aggregation to your table in the red marked line. In this aggregation don't forget to add as many cells as you need!

I also noticed that you have not chosen sap.m as your default library in the XML definition since you use <m:Label text="{OrdItab/Orderdt}" /> to create another mobile Label. You would also have to add this m in front of your table if you want to use sap.m table. I've done this and highlighted it as well.

Former Member
0 Kudos

Hi Dirk,

Thanks now no error is coming but output is not coming can u tell me how to check that in link i passed <Link text="{OrdItab/Orderd}" > as well.

0 Kudos

Hi,

good. Now we can look at the model integration. Where is that done in your source code? Can you provide the source code?

Can you provide the model that you are trying to use?

Former Member
0 Kudos

Hi dirk,

See i passed value like this in items

items=  "{/OrdItabSet?$filter=CustId eq '155719'}"

data is coming in table but its repeating in all the rows

0 Kudos

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...

Answers (3)

Answers (3)

saivellanki
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

No am not using openUI5.

saivellanki
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

custId is user input.

Former Member
0 Kudos

Hi sai,

By mistake its Rows.Actually am using items.

saivellanki
Active Contributor
0 Kudos

Hi Sham,

No need to bind the items again. You can apply filter to the table binding Data like this -


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

var custId = +your cutomer ID value+;          //Get your Customer ID value into a variable

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

oTable.getBinding("items").filter(oFilters, "Application");

Regards,

Sai Vellanki.

Former Member
0 Kudos

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.