Skip to Content
0

Count after filtering table oData

Mar 07 at 02:05 PM

46

avatar image
Former Member

Hi,

I am trying to get a count of rows in my table after applying a filter. I tried different methods including the following but with no success:

- oTable.getBinding().getLength()

- oTable.getItems().getLength()

I should get a count of 2 (the items are filtered in my view and only 2 rows are displayed) but I somehow get 0...

Here is my code :

//Table and binding
var oTable = this.getView().byId("tableLetMessages");
var oBinding = oTable.getBinding("items");
            
//Filtering
var aFilter = new sap.ui.model.Filter([
        new sap.ui.model.Filter("C_ID_MATCH", sap.ui.model.FilterOperator.EQ, numMatch),
        new sap.ui.model.Filter("PLAYER", sap.ui.model.FilterOperator.EQ, IDjoueur1),
        ],true);
            
//applying the filter
var oFilter = oBinding.filter(aFilter);
            
//Getting the count ???
var oTableItem = oTable.getItems();
var oTableLength = oTable.getBinding("items").getLength();
console.log(oTableItem.length)
console.log(oTableLength)

Many thanks,

Marianne

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Jun Wu Mar 07 at 04:37 PM
0
var oTableLength = oTable.getBinding("items").getLength();

I tried with jsonmodel, it gives me the right result.

your table bound to odata model directly?
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Mar 08 at 08:51 AM
0

Hi Jun Wu,

thank you for your input. My table is bound to the odata model directly via oData services. The above method isn't working.

Share
10 |10000 characters needed characters left characters exceeded
Raghav Rathor Mar 08 at 11:51 AM
0

Hi Marianne,

Try with the below code.

var totalCount = this.getView().byId("YourTableId").getItems();

this.getView().byId("YourTableId").setCount(totalCount.length);

Regards,

Raghav Rathor

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Mar 12 at 02:31 PM
0

Hi Raghav,

thank you for answer. When trying the code, I get an error message :

this.getView().byId("YourTableId").setCount(totalCount.length) is not a function

Share
10 |10000 characters needed characters left characters exceeded