on 10-15-2015 12:57 PM
Hi,
I try to get the binding information of columns of a sap.m.table in JavaScript but I can´t figure out how to do that.
This is my table definition (shortened example):
<Table id="tblSystemSelection" inset="false" items="{/Systems}" mode="SingleSelectMaster" width="auto">
<columns>
<Column>
<Label text="Column A"/>
</Column>
<Column>
<Label text="Column B"/>
</Column>
</columns>
<items>
<ColumnListItem>
<Text text="{MyColumnA}"/>
<Text text="{MyColumnB}"/>
</ColumnListItem>
</items>
</Table>
Now, in JavaScript I would like to get the binding paths "MyColumnA" and "MyColumnB".
I can get the table object and the binding info for the "items" collection:
var oTable = sap.ui.getCore().byId("tblSystemSelection");
var oItemsBinding = oTable.getBinding("items");
I can also get the cells of the item template:
oBindingInfo.template.getCells()
But nowhere I can find the binding path information "MyColumnA" and "MyColumnB".
Does anyone know how to get them?
Thanks and best regards,
Sebastian
You can try something like this.
var aBindingInfos = oTable.getBindingInfo('items').template.getCells().map(function(oCell){
return oCell.getBindingInfo('text').parts[0].path;
});
console.log(aBindingInfos) // ["MyColumnA","MyColumnB"]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sebastian,
I could see in your xml view that you haven't done any columns binding with model. They are hard-coded as "Column A" and "Column B" for text property using label control. If you just wanted to get hold of the columns, you can just say like this -
var oTable = this.getView().byId("yourTableID"); //Your Table ID
oTable.getColumns(); //This will fetch you the columns array and you can do [0] [1] ....... to get hold of specific column
If you're looking on something about the columns binding and retrieving them using the method oTable.getBinding("columns"), then will this JSBin help? JS Bin - Collaborative JavaScript Debugging
Click on the Columns Binding button, you will get the binding path and the model associated with that path as alert. Please correct if my understanding is wrong with regard to your requirement.
Regards,
Sai Vellanki.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sai Vellanki,
I got already to that point. But I don´t know how to fetch the property value "MyColumnA". In your JS Bin the value of oBindingPath is "/modelData/columnsData". But this is not what I want to retrieve. In your example I would like to retrieve "Product" and "Weight":
<cells>
<Text text="{Product}" />
<Text text="{Weight}" />
</cells>
Do you have an idea how to do that?
Thanks, Sebastian
Hi Sai Vellanki,
Thanks for your quick answer. However, it doesn´t help me here because this only seem to work for JSON model and not for oData model and second I can´t retrieve these information from the model because the table might only contain a subset of all available columns. But in the end I would like to get all columns (all binding paths of them) of the table defined in xml view. If this is not possible I have to do it statically in JavaScript - possible but not so nice.
Best regards,
Sebastian
Hi Sebastian,
The last option I would suggest: JS Bin - Collaborative JavaScript Debugging
Regards,
Sai Vellanki.
maybe this will shed some lights
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
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.