on 01-05-2015 3:36 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marc,
I think the following will be *much* easier for you, and it works regardless of client-side sorting/filtering:
var aSelectedIndices = oTable.getSelectedIndices();
for (var i=0; i<aSelectedIndices.length; i++) {
var oData = oTable.getContextByIndex(aSelectedIndices[i]);
// do whatever you want with the current oData object
}
EDIT: In your case, if you need the ID of the current object, simply use this in the for-loop:
var myId = oData.getObject().id;
Message was edited by: Robin van het Hof
Hi Marc,
I'm not aware of any examples, but it is in the sap.ui.table API: SAPUI5 SDK - Demo Kit
Personally, I have never found any use for the getRows() / addRow() / etc methods, I like to do everything model-based
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 !
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.