Justin
Justin

Reputation: 45

get table row count at load in sapui5

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:

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

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

Upvotes: 0

Views: 4259

Answers (1)

n01dea
n01dea

Reputation: 1580

please try to use in your controller of the view

...
onAfterRendering: function() {
    console.log(this.byId("oTable").getRows().length);
},
...

Upvotes: 1

Related Questions