0

I am trying this example in this I have to add total product count number i.e. total table rows display on screen.

https://sapui5.netweaver.ondemand.com/sdk/explored.html#/sample/sap.m.sample.Table/preview

When I try to Access length of JSON object i.e.:

<headerToolbar>
    <Toolbar>
        <Label text="Products"></Label>
        <Label text=""{ path: '/ProductCollection', formatter: 'sap.m.sample.Table.Formatter.totalFormatter' }""> </Label>
    </Toolbar>
</headerToolbar>
totalFormatter:function(results) { return results.length; }

I get SAPUI5 is not render error:

Uncaught TypeError: Cannot read property 'length' of undefined

Mike
  • 14,010
  • 29
  • 101
  • 161
Kitty
  • 179
  • 6
  • 13
  • 29
  • Maybe it would be helpful if you´d show some of your code. If you´re using databinding with your table you can simply print the size of the aggregation bound to the table but let´s see some code first to be more specific to your use case. – Tim Gerlach Aug 04 '14 at 07:04
  • I am trying this example in this I have to add total product count number i.e. total table rows display on screen https://sapui5.netweaver.ondemand.com/sdk/explored.html#/sample/sap.m.sample.Table/preview – Kitty Aug 04 '14 at 08:03
  • What Tim meant is, what have you tried yourself to get the total number of rows displayed? Where did you get stuck? – Qualiture Aug 04 '14 at 11:19

1 Answers1

0

I answer your question by modifying the code of your example.

  1. Edit the Table.view.xml, add one label in the Toolbar.
<headerToolbar>
    <Toolbar>
        <Label text="Products"></Label>
        <Label text=""
            {
                path: '/ProductCollection',
                formatter: 'sap.m.sample.Table.Formatter.totalFormatter'
            }"">
        </Label>
    </Toolbar>
</headerToolbar>
  1. Edit the formatter.js, add one method totalFormatter.
totalFormatter:function(results) {
    return results.length;
}

Then you will get the total table row.

The basic idea is to utilize the Calculated Fields of Data binding to get the result length. The documentation can be found here.

Mike
  • 14,010
  • 29
  • 101
  • 161
Haojie
  • 5,665
  • 1
  • 15
  • 14
  • When I try to Access length of JSON Object i.e totalFormatter:function(results) { return results.length; } I get SAP UI is not render error >> Uncaught TypeError: Cannot read property 'length' of undefined – Kitty Aug 05 '14 at 12:06