I want to fire "handleRowPress" when I press a table item. This is my code:
showTable: function(){
var oData=convertDataTable(testDataInput);
//make sure table id suffix is set (this is necessary for personalization)
var oTable = new sap.m.Table('testTable', {
headerToolbar: new sap.m.Toolbar({
itemPress: "alert('pippo')",
content: [
new sap.m.ToolbarSpacer({})
]
})/*,
columns: oData.cols.map(function (colname) {
//make sure column id suffix is set
return new sap.m.Column(colname, { header: new sap.m.Label({ text: colname })});
})*/
});
oTable.setModel(new sap.ui.model.json.JSONModel(oData));
for(var i=0; i<oTable.getModel().getProperty("/cols").length; i++){
oTable.addColumn(new sap.m.Column(oTable.getModel().getProperty("/cols")[i], { header: new sap.m.Label({ text: oTable.getModel().getProperty("/cols")[i] })}));
}
oTable.bindAggregation("items", "/items", new sap.m.ColumnListItem({
cells: oTable.getModel().getProperty("/cols").map(function (colname) {
return new sap.m.Label({ text: "{" + colname + "}" });
})
}));
//oTable.setProperty("selectionChange","handleRowPress");
//oTable.setProperty("itemPress", "handleRowPress" );
//oTable.setProperty("select", "handleRowPress" );
oTable.attachItemPress("handleRowPress");
var myPage=this.byId("pageOperation");
myPage.addContent(oTable);
},
handleRowPress : function(){
console.log("clicked on item!!!!");
//console.log(event);
}
Why can't I do it? If I try to set the property "itemPress" (comment lines) it doesn't seem to set it.
How can I set the function without an XML view but only with js
code?