cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 how to read table column bound field

0 Kudos

Hi All,

Can you help me to know how I can read table column bound field values like I have a table in XML lets say "otable" and one of the column is "Expected Delivery Date" which is bind to "Erdate" of my model.

So I want to read my table column bound filed at runtime

Thanks

Rajesh

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi All,

Sorted, I am reading metadata of OData to know data type of each filed and checking with the table bind items

var aColumns = oTable.getColumns();
var aItems = oTable.getItems();
var aTemplate = [];
var listDates = this.getDateTypesMeatModel(oModel);

for (var i = 0; i < aColumns.length; i++) {
var oColumn = {
name: aColumns[i].getHeader().getText(),
template: {
content: {
path: null,
formatter: null
}
}
};
if (aItems.length > 0) {
oColumn.template.content.path = aItems[0].getCells()[i].getBinding("text").getPath();
if(listDates.indexOf(oColumn.template.content.path) > -1){
oColumn.template.content.formatter = that.fnDate;
}else{
oColumn.template.content.formatter = that.rtnText;
}
}
aTemplate.push(oColumn);
}

In above code "listDates" is an array of date fields from metadata

		getDateTypesMeatModel : function(oModel){
			var listDateFields = [];
			var serMetadata  = sap.ui.getCore().getModel(oModel).getServiceMetadata();
			var modelSchema = serMetadata.dataServices.schema[0];
			var lenEntities = modelSchema.entityType.length;
			
			for(var i =0; i<lenEntities ;i++){
				var lenProps = modelSchema.entityType[i].property.length;
				var ObjProp = modelSchema.entityType[i].property;
					for(var j =0; j<lenProps; j++){
						if(ObjProp[j].type === "Edm.DateTime"){
							listDateFields.push(ObjProp[j].name);
						}
					}
			}
			return listDateFields;
		}

Thanks

Answers (2)

Answers (2)

former_member227918
Active Contributor
0 Kudos

check this tread, will help you,

https://answers.sap.com/questions/161155/how-to-get-values-from-table-without-clicking-on-t.html?chi...

if you wants to get value of clicked row only, follow same way using bindingcontext of current row only.

0 Kudos

Hi Akhilesh,

I want to read bind filed to column, actual requirement is I need to export table data to excel/csv and apply the formmater based on the filed mapped(for ex ErDate- date format).

So in export method first I read and construct table columns and here itself I should know which column it is and to which OData field its mapped..so that I can attach respective formatter.

In below code I have applied formatters(just for example), type of formatter should apply for that related OData filed

that.fnDate

that.rtnText
exportToExcel: function(oTable) {
var that = this;
var aColumns = oTable.getColumns();
var aItems = oTable.getItems();
var aTemplate = [];
for (var i = 0; i < aColumns.length; i++) {
if (aColumns[i].getHeader().getText().indexOf("Date") !== -1) {
var oColumn = {
name: aColumns[i].getHeader().getText(),
template: {
content: {
path: null,
formatter: that.fnDate
}
}
};
} else {
var oColumn = {
name: aColumns[i].getHeader().getText(),
template: {
content: {
path: null
// formatter: that.rtnText
}
}
};
}
if (aItems.length > 0) {
oColumn.template.content.path = aItems[0].getCells()[i].getBinding("text").getPath();
}
aTemplate.push(oColumn);
}
var oExport = new sap.ui.core.util.Export({
// Type that will be used to generate the content. Own ExportType’s can be created to support other formats
exportType: new sap.ui.core.util.ExportTypeCSV({
separatorChar: ",",
charset: "utf-8"
}),
// Pass in the model created above
models: oTable.getModel(),
// binding information for the rows aggregation
rows: {
path: "/"
},
// column definitions with column name and binding info for the content
columns: aTemplate
});
oExport.saveFile().always(function() {
this.destroy();
});
},

Thanks

Rajesh

former_member227918
Active Contributor
0 Kudos

what is your issue here? create new proper thread for this to make people help you better.

Former Member
0 Kudos

Hi,

1)Either read directly from the Model itself in case of JSONModel and bind that model to table

2)Or in Controller call a method this.getView().getModel('oModel'). And then read from that model the value you are interested in.

using .oData or getProperty("/") etc.

Thanks,

Den