Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: SAPUI5 Table with odata update with hidden columns?

$
0
0

Bheki,

 

I still used the 0px column on my table to get the key data from the DOM, but I think that you could use the onRowSelect event to get the full context of the data model associated with the row.

Something like this:

onRowSelect: function(oEvent) {  var data = oEvent.getSource().getModel();  var oTable = oEvent.getSource();  var ctx = oTable.getContextByIndex(oTable.getSelectedIndex());  var provider_id = data.getProperty("PROVIDER_ID",ctx);<do other bound property lookups here>

 

 

How I actually implemented it right now looks like this:

 

View code - create the table, add toolbar and set the table column for the k to 0px.so that users cannot see it:

var oTable = new sap.ui.table.Table("tblMemberThresholds", {  editable: false,  visibleRowCount : 8,  selectionMode: sap.ui.table.SelectionMode.Single,  toolbar : new sap.ui.commons.Toolbar({  items : [ new sap.ui.commons.Button({  text : "New Threshold Values",  press : function() {oController.Create();}}),  new sap.ui.commons.Button({  text : "Update Selected Threshold Values",  press : function() {oController.Update();}}),  new sap.ui.commons.Button({  text : "Delete Selected Threshold Values",  press : function() {oController.Delete();}}),  ]  }),  });
oTable.setNoData(new sap.ui.commons.TextView({text: "Sorry, no data available!"}));
// Table Column Definitions  oControl = new sap.ui.commons.TextField().bindProperty("value", "MEMBER_ID");
oTable.addColumn(new sap.ui.table.Column("colMEMBER_ID", {label : new sap.ui.commons.Label({text : "MEMBER_ID"}),template : oControl, sortProperty : "MEMBER_ID", filterProperty : "MEMBER_ID", filterOperator: sap.ui.model.FilterOperator.EQ, flexible : false, width : "0px"}));

Controller code, bind the data to the table:

var oModel = new sap.ui.model.odata.ODataModel("../../../services/member_thresholds.xsodata/", false);  var oTable = sap.ui.getCore().byId("tblMemberThresholds");  oTable.setModel(oModel);  var Context = "/MEMBERS("+viewingMemberId+")/THRESHOLDS";  var sort1 = new sap.ui.model.Sorter("MEASUREMENT_NAME");  oTable.bindRows(Context, sort1);

Controller code - pull the data from the selected row using a button press event from the toolbar on the table:

Update : function() {  var oTable = sap.ui.getCore().byId("tblMemberThresholds");  var i = oTable.getSelectedIndex();  if(i == -1) {  alert("Please Select a row to Update");  return;  } 
else if(i>=0){
var selectedRow = oTable.getContextByIndex(i);

Once you have the key field for the selected row, you can get all other data from the table using selectedRow.getProperty('myProperty') and use it in your create/update calls. 

 

Hope that helps. 

 

Jim Giffin


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>