0
votes

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");
1
Could you update your question? On load of what exactly, data? How do you bind the data to the table? And which table are you using (sap.ui.table.Table or sap.m.Table)? I assume sap.ui.table.Table because of getRows. Please, show us some more code.Boghyon Hoffmann

1 Answers

1
votes

please try to use in your controller of the view

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