on 03-07-2018 2:05 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marianne,
Try with the below code.
var totalCount = this.getView().byId("YourTableId").getItems();
this.getView().byId("YourTableId").setCount(totalCount.length);
Regards,
Raghav Rathor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
var oTableLength = oTable.getBinding("items").getLength();
I tried with jsonmodel, it gives me the right result.
your table bound to odata model directly?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.