cancel
Showing results for 
Search instead for 
Did you mean: 

Bind button in row to the table row

Former Member
0 Kudos

I have an Edit and Delete button in each row of an oData table. I wanted to know how to bind each button to its respective row, so when I click a particular button, I can edit and save a particular row.

Here's what my table looks like.

Accepted Solutions (1)

Accepted Solutions (1)

surendra_pamidi
Contributor
0 Kudos

Hi Saneth,

On click on buttons, change the model and set the model to table inside press function.

It will reflect in table immediately.

And if you tell which type of operations you want  to do, we can help better..

Answers (1)

Answers (1)

former_member91307
Contributor
0 Kudos

Hi Saneth,

current binding context could be used to edit and delete row

below example might help

http://jsbin.com/uxokuc/362/edit

Thanks and Regards, Venkatesh

Former Member
0 Kudos

Hi Venkatesh,

Thank you for the example. I tried this method, and it works. However, once initally loading the table, it starts of as an editable table. After using the Edit Save button once, it begins to work the way it should.

Any idea why this is happening?

Here's the code.


//TABLE CREATION

oTable = new sap.ui.table.DataTable({

  id: "productTable",

    title: "Carbon Footprint Data",

    selectionMode : sap.ui.table.SelectionMode.Single,

  visibleRowCount: 20,

  editable : false,                                  

       enableColumnReordering:false,

    });

//COLUMN CREATION

oTable.addColumn(new sap.ui.table.Column({

    label: new sap.ui.commons.Label({text:"Edit"}),

    template: new  sap.ui.commons.Button({text:"Edit", press: function(){

    var currentContext = this.getBindingContext();

             var oCurrentModel = currentContext.getModel();

             selectedProductID = oCurrentModel.getProperty("ID", currentContext);

             if(this.getText()==='Edit'){

              this.setText('Save');

              oCurrentModel.setProperty('editable',true,currentContext);  

             }

             else{

              this.setText('Edit');

              oCurrentModel.setProperty('editable',false,currentContext);

   }

              

    }}),

    width: "120px"

 

    }));