Skip to Content
avatar image
Former Member

SAP UI5 how to read table column bound field

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Apr 07, 2017 at 10:36 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 06, 2017 at 11:27 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 06, 2017 at 12:47 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded