on 04-06-2017 11:37 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
check this tread, will help you,
if you wants to get value of clicked row only, follow same way using bindingcontext of current row only.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.