Get row count in SAPUI5

I have sap.ui.Tableone that shows a list of entries. I want to get the number of records in the data.

I read the SAP UI 5 post on how to print a common table row , but that didn't help me.

This is the code for the table (the code for the columns has been removed to make the message smaller):

  <table:Table id="PickRecs" visibleRowCount="10" selectionMode="MultiToggle" visible="true" rows="{/downRecs}" >
    <table:title>
        <txt:Text text="{
      path: '/downRecs',
      formatter: 'Formatter.totalFormatter'
    }">
        </txt:Text>
        <Label text="possible records to export"></Label>

    </table:title>
    <table:columns>
      .......
    </table:columns>
 </table:Table>

This is formatter.js:

totalFormatter:function(results) {

    return results.length;
 }

I would like to show how many rows are in the table, using an array downRecsas the source of all the records. For example: 3 possible reports for export.

This value may vary depending on some input fields on the screen, for example, they may choose to view all records for a product or only records for a specific client, etc.

? .

+4
4

, . , , , ListBinding , ListBinding factory .

, .

var oBinding = oTable.getBinding("rows"); 
oBinding.attachChange(function(sReason) {
    oYourTextField.setText(oBinding.getLength());
});

. jsbin

http://jsbin.com/kohozenina/1/edit?html,output

, , ControlModel, , , .

+6

{/downRecs/length}? .

, , . , .

- :

var oSource = oEvent.getSource();
var oItems = oSource.getModel().getProperty("/downRecs");
oItems.push({
    "Property1": "Value1", 
    "Property2": "Value2", 
    ...
});
oSource.getModel().setProperty("/downRecs", oItems);
0
 xml view 
    <Button text="click" press="click"></Button>
        <Table id="idProductsTable"
    inset="false"
    items="{/ProductCollection}">
    <headerToolbar>
      <Toolbar>
        <Label id="idset" ></Label>
      </Toolbar>
    </headerToolbar>
    <columns>
      <Column 
        width="12em">
        <Text text="Product" />
      </Column>
      <Column
        minScreenWidth="Tablet"
        demandPopin="true">
        <Text text="Supplier" />
      </Column>
    </columns>
    <items>
      <ColumnListItem>
        <cells>
          <ObjectIdentifier
            title="{Name}"
            text="{ProductId}"
            class="sapMTableContentMargin" />
          <Text
            text="{SupplierName}" />
            </cells>
      </ColumnListItem>
    </items>
  </Table>

controller.js
onInit: function() {
    var data= {
        "ProductCollection": [
            {
                "ProductId": "1239102",
                "Name": "Power Projector 4713",
                "SupplierName": "Titanium"

            },
            {
                "ProductId": "2212-121-828",
                "Name": "Gladiator MX",
                "SupplierName": "Technocom"

            }]
            }
    var oModel = new sap.ui.model.json.JSONModel();
    oModel.setData(data);
    this.getView().setModel(oModel);
},
click:function(){
var count= this.getView().byId("idProductsTable").getItems().length;
var id= this.getView().byId("idset").setText("Record="+count);
alert("Record="+count);
}
0
source

there is also one way eayse

oTable._getRowCount ()

0
source

All Articles