on 10-01-2015 8:14 AM
HI,
I have created one table in SAPUI5 using XML View.
I want to get the selected record for the same and please let me know the how to edit the selected row.
I have done binding in the controller.
Below is my code for XML VIEW.
XML View.
<mvc:View
controllerName="xmltabelr.xml"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:u="sap.ui.unified"
xmlns:c="sap.ui.core"
>
<Page
showHeader="false"
enableScrolling="false"
class="sapUiContentPadding">
<content>
<Table
id="table"
selectionChange="press"
>
<columns> <!-- sap.m.Column -->
<Column>
<ObjectIdentifier title="sales"/>
</Column>
<Column>
<ObjectIdentifier title="amount"/>
</Column>
<Column>
<ObjectIdentifier title="text"/>
</Column>
</columns>
</Table>
</content>
</Page>
</mvc:View>
Controller ,js
Init:function ()
var vData= [
{assID:"EM123456", name:"Bharath S", linkText:"Cognizant Technology Solutions", href:"http://www.cognizant.com", gender:"Male", mobile:"9934307162", rating:5},
{assID:"EM263521", name:"Arun M", linkText:"Cognizant Technology Solutions", href:"http://www.cognizant.com", gender:"Male", mobile:"9786721460", rating:3},
{assID:"EM323455", name:"Anitha", linkText:"Cognizant Technology Solutions", href:"http://www.cognizant.com", gender:"Female", mobile:"9524396759", rating:4},
{assID:"EM237652", name:"Ganesh", linkText:"Cognizant Technology Solutions", href:"http://www.cognizant.com", gender:"Male", mobile:"9876543210", rating:1},
{assID:"EM398454", name:"Ajai", linkText:"Cognizant Technology Solutions", href:"http://www.cognizant.com", gender:"Male", mobile:"9576113218", rating:4},
{assID:"EM348092", name:"Pranav", linkText:"Cognizant Technology Solutions", href:"http://www.cognizant.com", gender:"Male", mobile:"9576113218", rating:5}
];
var oJson = new sap.ui.model.json.JSONModel();
oJson.setData(vData);
this.getView().setModel(oJson);
var oTable = this.getView().byId("table");
var oTemplate = new sap.m.ColumnListItem({
cells: [ new sap.m.Text({
text: "{assID}"
}),
new sap.m.Text({
text: "{assID}"
}),
new sap.m.Text({
text: "{assID}"
}),
] });
oTable.setMode(sap.m.ListMode.SingleSelect);
oTable.bindAggregation("items","/",oTemplate);
)
press: function(ooControlEvent) {
var oSelectedItem = ooControlEvent.getParameters.listItems;
var oSelectedItem1 = ooControlEvent.getParameters.listItem;
var oSelectedItem2 = ooControlEvent.getParameters;
var oSelectedItem3 = ooControlEvent.getSource;
alert(oSelectedItem3);
var select = ooControlEvent.getSelectedItem();
},
Please let me know how i can achieve it.
THanks
Nishant
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sai,
Thanks for your help, Can you please let me know how the logic behind this
I think the the importing parameter is sufficient for getting the parameter. so why we go for this.
var oModel = sap.ui.getCore().getModel().getProperty(oEvent.getSource().getBinding("items").getContexts()[oEvent.getSource().indexOfItem(oEvent.getParameters().listItem)].sPath); | ||
alert(JSON.stringify(oModel)); | ||
} |
Why we need to use the sap.ui.getCore().
Thansk
Nishant
Nishant,
Actually you know what you can scrap that logic onPress (selectionChange) event of table, you can simply write like this -
onPress:function(oEvent){
var oSelectedListItem = oEvent.getParameter("listItem"); //Get Hold of List Item selected.
var oBindingContext = oSelectedListItem.getBindingContext(); //Get Hold Binding Context of Selected List Item.
var oPath = oBindingContext.getPath(); //Get Hold of Binding Context Path
var oModel = sap.ui.getCore().getModel().getProperty(oPath); //Get the binding model.
alert(JSON.stringify(oModel)); //Alert the model Data
There are many ways to pull the selected table list item data. At high level, either you can pull the data from table control / by model.
It is highly recommended that to pull the data of selected Item using model. I have debugged the above code and see the result what it comes for each statement. Hope you will understand.
Regards,
Sai Vellanki.
I agree that we can simplify the Sai's code like this
JS Bin - Collaborative JavaScript Debugging
Thanks
-D
Please mark this as the correct solution Nishant . I came here because this was on the unanswered questions list and this is clearly not the case.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.