Skip to Content
avatar image
Former Member

UI5 Table getRows() returns rows array size below the visibleRowCount limit

Hi,

When my table rows # exceed the numbers of visibleRowCount (be the rows then available thru scrollbar or navigation pages), i can't access programmatically the rows objects selected (and no access to model, binding path, etc...);

Indeed, it is the API Table.getRows() api that only returns the first # of rows < visibleRowCount, whatever the current table view status is (scrolled, paginated, or not)

I've written a short sample on JSBin here

[...]

  var idx = oTable.getSelectedIndex();

  var row = oTable.getRows()[idx];

  //row returns undefined if idx > visibleRowCount

   [...]

I'm using version 1.24.4.

Does anybody have a clue of what i'm missing here to get access to this row objects  ?

Is it an expected behaviour ?

Note that, as workarounds, i tried:

a) access these by using

Table.attachRowSelectionChange{function (oEvent)}

oEvent.mParameters.rowContext.sPath

oEvent.mParameters.rowContext.oModel

etc...

But that is very cumbersome as i'd have to manage my own maps for multiple selections & selecting/unselecting...

b) don't use the rows to get back to the model, directly hardcode mybindingPath="/model/" + idx;

But that does not match if the index list is altered thru a table sorting for example.

Thanks a lot for any clue!

Marc

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Jan 05, 2015 at 04:38 PM

    Why do you want the rows anyway? Isn't it just more convenient to get the table's binding context (i.e. the bound objects for the rows) based on the selected rows?

    As an added benefit, you will also have access to fields which are not displayed in your table

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 05, 2015 at 04:33 PM

    We'll need to subtract the first visible row.

    var idx = oTable.getSelectedIndex() - oTable.getFirstVisibleRow();

    var row = oTable.getRows()[idx];

    This due to the implementation of the sap.ui.table.Table control. For this control, getRows is the getter for the rows aggregation which will never contain more elements than visibleRowCount but instead binds the elements in the aggregation against a certain range of records in the model. The range is always [firstVisibleRow; firstVisibleRow + visibleRowCount].

    - Max

    P.S.

    What are you trying to achieve anyway?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks Maximilian,

      However, i just retested to be sure, but the getRows() always return the first ones, and does not update dynamically given thenavigation; hence, getRows() is always in the range [0;visibleRowCount]), and not [firstVisibleRow; firstVisibleRow + visibleRowCount].

      Maybe I'm missing something ?

      To answer the questions, here is the larger picture of what i'm trying to achieve:

      I just want to retrieve the model bindings of a multi-selection on a list that is larger than the visibleRowCount. I actually do not care about the rows objects, I only need them to retrieve rows[selectedIndex].getBindingContext(), which gives me the path to get the needed model properties.

      See below my code for removing the selected entries of the table:

      new sap.ui.commons.Button({

        text: "Remove Entries",

        press: function() {

        var idxs = oJobsTable.getSelectedIndices();

        var rows = oJobsTable.getRows();


        for (i=0;i <idxs.length;i++) {

        var row = rows[idxs[i]];


        var aPath = row.getBindingContext();   

        var entryID = aModel.getProperty(aPath + "/id");

        oController.removeEntry(entryID);

        }


        oController.refreshData();

        }


      If any idea to make this simplier (without going into the rows api) i'm fine :-) !

      However, keep in mind i need to support the table sorting (hence why it seemed to me i needed to really get the bindingContext from the row)...

      Thanks !

  • Jan 05, 2015 at 04:25 PM

    Hi,

    oTable.getRows() will return only visible rows count.

    I have written code in rowSelectionchange. Not sure you are looking like this, but pls have a look.

    Add comment
    10|10000 characters needed characters exceeded