1

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?

Neeku
  • 3,646
  • 8
  • 33
  • 43
padibro
  • 1,324
  • 10
  • 56
  • 95

1 Answers1

0

you can set the handler in the table-constructor as function:

var oTable = new sap.m.Table({
    itemPress: function(){
        console.log("clicked on item");
    }
});

or set it in the constructor as reference

var oTable = new sap.m.Table({
    itemPress: this.handleRowPress
});

or attach the function over the created Table-object

oTable.attachItemPress(this.handleRowPress);
herrlock
  • 1,454
  • 1
  • 13
  • 16
  • try to debug the entire code, it can be that the function will not be set because there is another error – herrlock Jun 20 '14 at 12:20
  • I try to set the function to fire into xml view `
    ` But not work..
    – padibro Jun 20 '14 at 12:50
  • if I use `console.log(tablePippo.getProperty("itemPress"));` inside the controller it returns `Uncaught Error: Property "select" does not exist in Element sap.m.Table#operationDetail--testTable` – padibro Jun 20 '14 at 13:09
  • Please note that `itemPress` was introduced in UI5 version 1.20 so make sure to have the latest version in your project. – Tim Gerlach Jun 20 '14 at 13:52
  • where i can see the version? i retrieve from th web the libraries! src="https://openui5.netweaver.ondemand.com/resources/sap-ui-core.js" Really this is the problem?? – padibro Jun 20 '14 at 13:57
  • It's just a possible problem. Check the Version in your running application pressing CTRL+ALT+SHIFT+S – Tim Gerlach Jun 20 '14 at 14:24
  • the version is 1.20.7 This is My view http://pastebin.com/Qs88E8Gs `tap="retrieveData"` on the form work but `itemPress="retrieveData"` not work. And this is the controller http://pastebin.com/fwCVhTpw – padibro Jun 20 '14 at 14:59