on 2015 Mar 19 8:27 AM
Hi,
Please share recommendations to count the objects in JSON Model as overall and after applying some filters.I generally do this for Odata Models with response.length after doing some read operation of model along with filters.
Do we have such possibility for JSON Model? Please share suggetions.
Regards,
Koti Reddy
When there is JsonModel, filtering is applied through binding not the model itself, model remains the same. So to calculate number of items you have to get length of the contexts in binding (sap.ui.model.ListBinding.getContexts().length)
so something like
var oBinding = oTable.getBinding("items");
oIcontabfilter.setCount(oBinding.getContexts().length);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I got solved by reading the data in the model to get the count as I need count before clicking any IconTabFilter.
From Binding/From UI , I believe it is possible to count after selecting the filter.
var countm=0;
var countn=0;
var countl=0;
var countp=0;
var counta=oModel2.getData().modelData.length;
this.getView().byId("iconTabAll").setText("All p ("+counta+")");
for(var i=0;i<counta;i++){
flag3=oModel2.getProperty("/modelData")[i].Zfield3;
flag2=oModel2.getProperty("/modelData")[i].Zfleld2;
flag4=oModel2.getProperty("/modelData")[i].Zfleld4;
flag7=oModel2.getProperty("/modelData")[i].Zfleld7;
if(flag3!=""){
countm=countm+1;
}
if(flag2!=""){
countn=countn+1;
}
if(flag4!=""){
countl=countl+1;
}
if(flag7!=""){
countp=countp+1;
}
}
this.getView().byId("iconTabM").setText("Major ("+countm+")");
this.getView().byId("iconTabN").setText("Num ("+countn+")");
this.getView().byId("iconTabL").setText("last ("+countl+")");
this.getView().byId("iconTabP").setText("product ("+countp+")");
Regards,
Koti Reddy
Hi Koti,
This gives the no. of records in table.
var oModel = new sap.ui.model.json.JSONModel();
oModel.attachRequestCompleted(function(oEvt){
console.log(this.getView().byId("Table Id").getItems().length);
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData( aData);
console.log(oModel.oData.length);
This gives you the number of objects in JSON
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Koti, I think that if you want know the number of rows once the filter was applied, you need get count from control and not from model. I show you an example getting count from sap.m.Table:
Regards,
Pau
Hi,
In my scenario , it is not useful as I want to display table data under specific Icontabfilter without selecting them.
Same table is used for all Icontabs.So If I read data count from table UI , Count displays only one Icon tab filter related tab count.
I want to read JSON Model data to display data length related to all Icontab filters.
Regards,
Koti Reddy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
71 | |
11 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.