cancel
Showing results for 
Search instead for 
Did you mean: 

JSON Model Count

Former Member
0 Kudos
1,985

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

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);

Qualiture
Active Contributor
0 Kudos

Best answer!

Former Member
0 Kudos

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

Answers (3)

Answers (3)

santhu_gowdaz
Active Contributor
0 Kudos

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);

                });

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

I am looking for count after doing some filter operations on JSON Model.

Scenario :

Implemented Icon tab Filters to filter JSON Model data. I want to show table rows count ( for each tab filter).

In this case how to read json model objects count considering filters.

Regards,

Koti Reddy

PMarti
Active Participant
0 Kudos

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:

JS Bin - Collaborative JavaScript Debugging&lt;/title&gt; &lt;link rel=&quot;alternate&quot; type=&q...

Regards,

Pau

Former Member
0 Kudos

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

ChandrashekharMahajan
Active Contributor
0 Kudos