Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get table row count in SAPUI5

Tags:

sapui5

I have an sap.ui.Table that shows a list of records. I want to get a count of the records in the data.

I have read the post SAP UI 5 how to print total table row , but it hasn't helped me.

This is the code for the table (code for the columns has been removed to make the post 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 the formatter.js:

totalFormatter:function(results) {

    return results.length;
 }

I would like to display how many rows there are in the table using the array downRecs as the source of all the records. For example: 3 possible records to export.

This value can change based on some input fields on the screen, for example they can choose to see all records for a product or only records for a certain customer, etc.

How can I get this updated count of the records? This value is shown on the toolbar or title of the table.

like image 655
user3861284 Avatar asked Dec 10 '14 20:12

user3861284


1 Answers

Binding length is not a property that you can bind. Also what is written at the reference link is not correct because you cannot initialize ListBinding for a property, ListBinding needs template or factory and multiple aggregation cardinality.

To get informed about updated count of the records you should attach to the change event of the binding.

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

see jsbin and press column header for filter menu

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

We know this is a little bit cumbersome and we are working on a ControlModel which you can bind something that fires change event like binding length or number of the selected items.

like image 106
aborjinik Avatar answered Sep 18 '22 17:09

aborjinik