Skip to Content

How to update cell of a selected table row on button click in sap ui5

Mar 17, 2017 at 05:29 PM


avatar image
Former Member

Is that possible to update it on row selection change of table

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

avatar image
Former Member Mar 17, 2017 at 06:53 PM

Normally, I bind my table to an Odata model. So i don't directly change the data in the table, I update data in the database that is related to that table row, then refresh the table row binding.

So in the click event of the button,

  • Your function should get the table control object and get the selected indexes.
  • Then for each table row index get the related sPath.
  • Using sPath, get the data for that table row from your odata model.
  • This data can then be used to update the database appropriately.
  • After those updates are successful, refresh your table binding.
//// View, button definition ///
var btnWorkflow = new sap.m.Button({ id: "btnWorkFlow", text: "Workflow", enabled: bEnabled, icon: "sap-icon://workflow-tasks", tooltip: "Submit Selected Rows to Workflow", press: oController.submitToWorkflow }); //// Controller press function ////// submitToWorkflow: function(evt){ //User clicked the submit to Workflow button //Find out what rows user selected and process them WebContent.homepage.eacinput.model.workflow.processWorkflowRequest(evt); //Auto refresh table binding after workflow process sap.ui.controller("WebContent.homepage.eacinput.main").refreshEACSubmitTable(); }, processWorkflowRequest: function(evt){ //User clicked the submit to Workflow button //1.Find out what rows user selected //1.Get a list of all selected table rows. var aIndices = sap.ui.getCore().byId("EACInputTable").getSelectedIndices(); if(aIndices.length !== 0){ //From selected row data, build array of unique Workflow Request ID's for(var i = 0; i < aIndices.length; i++){ var sPath = sap.ui.getCore().byId("EACInputTable").getContextByIndex(aIndices[i]).sPath; var data = sap.ui.getCore().getModel("EACInput").getProperty(sPath); //This is where you would look at the data in the row and update the database }
} refreshEACSubmitTable: function(){ //if table rows are already bound then just refresh row bindings and scroll to same index if(sap.ui.getCore().byId("EACInputTable").getBinding("rows")){ var scrollIndex = sap.ui.getCore().byId("EACInputTable").getFirstVisibleRow(); sap.ui.getCore().byId("EACInputTable").setFirstVisibleRow(0); sap.ui.getCore().byId("EACInputTable").getBinding("rows").refresh(); sap.ui.getCore().byId("EACInputTable").setFirstVisibleRow(scrollIndex); //refresh totals also sap.ui.getCore().byId("EACInputTable-Footer").getBinding("rows").refresh(); }else{ sap.ui.controller("WebContent.homepage.eacinput.main").bindEACInputTable(); } },
10 |10000 characters needed characters left characters exceeded
A K Jun 09, 2017 at 02:32 PM

yes, it is possible.

You should use select event to get the selectedItems from the table.


Karthik A

10 |10000 characters needed characters left characters exceeded