cancel
Showing results for 
Search instead for 
Did you mean: 

Count after filtering table oData

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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

RaghavRathor
Explorer
0 Kudos

Hi Marianne,

Try with the below code.

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

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

Regards,

Raghav Rathor

Former Member
0 Kudos

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.

junwu
Active Contributor
0 Kudos
var oTableLength = oTable.getBinding("items").getLength();

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

your table bound to odata model directly?