Skip to Content
0

SAP UI5 how to read table column bound field

Apr 06, 2017 at 10:37 AM

127

avatar image

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

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

3 Answers

Best Answer
rajeshkumar rajeshkumar Apr 07, 2017 at 10:36 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
den colin Apr 06, 2017 at 11:27 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Akhilesh Upadhyay Apr 06, 2017 at 12:47 PM
0

check this tread, will help you,

https://answers.sap.com/questions/161155/how-to-get-values-from-table-without-clicking-on-t.html?childToView=161336#answer-161336

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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

0

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

0