Skip to Content
0

get table row count at load

Jun 29, 2017 at 07:56 PM

45

avatar image

Hi,

I am deploying over gateway with UI5 version 1.28 and my model is defined in controller and am able to get records in table from json. I am trying to get the number of records displayed in table on the load. I am able to do that on click of a button via sap.ui.getCore().byId("oTable").getModel("MyJsonData").oData.length

but I want to get this without an action and on load only. Tried calling the same at init of controller but it does not work and returns undefined.

Tried few other options as below

sap.ui.getCore().getModel("MyJsonData").oData.lengthvia = undefined.

sap.ui.getCore().byId("oTable").getRows().length - does not work.

_getRowCount() - does not work

oTable.getBinding().getLength() - does not work

Anything else to try?

My code is as below: In View:

<code>var oTable = new sap.ui.table.Table("oTable",{
            selectionMode : sap.ui.table.SelectionMode.Single,
            selectionBehavior : sap.ui.table.SelectionBehavior.Row,
            visibleRowCount : 7,
            firstVisibleRow : 3,
            rowSelectionChange:oController.formatTable,
            fixedColumnCount : 2
        });

oTable.bindRows("MyJsonData>/");

Inside Component.js

<code>var oModel = new sap.ui.model.json.JSONModel("model/data.json");
this.setModel(oModel, "MyJsonData");
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Dennis Seah
Jun 30, 2017 at 05:33 AM
0

HI

I believe this will work for you

var oModel = new sap.ui.model.json.JSONModel("model/data.json");
oModel.attachRequestCompleted(function() {
console.log(this.getData().length);
}); this.setModel(oModel, "MyJsonData");
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi

In component.js I updated like this

var oModel = new sap.ui.model.json.JSONModel("model/data.json");

oModel.attachRequestCompleted(function() { console.log(this.getData().length);

oModel.setData(this.getData()); });

this.setModel(oModel, "MyJsonData");

console.log(oModel);

console.log(sap.ui.getCore().getModel("MyJsonData"));

I do get the length this way but the binding stops working for the table- not sure why - with no changes made to my view. Both the console statements return data.

If I put my earlier code the binding works.

0
Justin Kemp Jul 05, 2017 at 06:08 PM
0

Your answer was correct Dennis. Issue with my code. thanks

Share
10 |10000 characters needed characters left characters exceeded