Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 8150

Populate table columns dynamically using oData or SQL

$
0
0

Hi All,

 

I've created an application that accesses and renders a HANA table on a webpage. However, the tables columns are static and the headers are hard-coded.

 

Is there a way to dynamically display the table columns and headers without having to hard code it? So, when new columns are added to the table, I wont need to go back and write more code to accommodate the new column/s

 

Here's a sample of my table.

 

//Create Table  oTable = new sap.ui.table.DataTable({  id: "productTable",    title: "Carbon Footprint Data",    selectionMode : sap.ui.table.SelectionMode.Single,  visibleRowCount: 20,  editable : false,                                          enableColumnReordering:true    });      //Add Columns Statically - Want this to be done dynamically in case I add more columns to the table.    oTable.addColumn(new sap.ui.table.Column({  label: new sap.ui.commons.Label({text:"ID"}),  template: new sap.ui.commons.TextField().bindProperty("value","ID"),  sortProperty: "ID",  filterProperty: "ID"}));        oTable.addColumn(new sap.ui.table.Column({    label:new sap.ui.commons.Label({text:"Country"}),    template: new sap.ui.commons.TextField().bindProperty("value","Country"),    sortProperty: "Country",    filterProperty: "Country"}));      oTable.addColumn(new sap.ui.table.Column({    label:new sap.ui.commons.Label({text:"Emitter Type"}),    template: new sap.ui.commons.TextField().bindProperty("value","Emitter"),    sortProperty: "Emitter",    filterProperty: "Emitter"}));      oTable.addColumn(new sap.ui.table.Column({    label:new sap.ui.commons.Label({text:"Quarter - Year"}),    template: new sap.ui.commons.TextField().bindProperty("value","Quarter"),    sortProperty: "Quarter",    filterProperty: "Quarter"}));      oTable.addColumn(new sap.ui.table.Column({    label:new sap.ui.commons.Label({text:"Carbon Footprint"}),    template: new sap.ui.commons.TextField().bindProperty("value","Carbon_Footprint"),    sortProperty: "Carbon_Footprint",    filterProperty: "Carbon_Footprint"}));      //Data Binding      oTable.setModel(oModel);      oTable.bindRows("/CarbonData");        oTable.placeAt("master");

Can this be done with oData or SQL?

 

Thank you!


Viewing all articles
Browse latest Browse all 8150

Trending Articles



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