Skip to Content
avatar image
Former Member

Count after filtering table oData

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Mar 07 at 04:37 PM
    var oTableLength = oTable.getBinding("items").getLength();
    
    I tried with jsonmodel, it gives me the right result.
    
    your table bound to odata model directly?
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 08 at 08:51 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 08 at 11:51 AM

    Hi Marianne,

    Try with the below code.

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

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

    Regards,

    Raghav Rathor

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 12 at 02:31 PM

    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

    Add comment
    10|10000 characters needed characters exceeded