SylwekFr
SylwekFr

Reputation: 328

SAPUI5 format a data from a format in a model with binding

Environement

Framework: SAPUI5 V1.38.39

Question

For date in view from SAP UI5 it is possible to format the date from a date format such as :

<Text 
    text="{
      path:'HandlingUnitMultipleModel>PlannedDeliveryDate',
      type:'sap.ui.model.type.DateTime',
      formatOptions: { UTC:true, pattern: 'dd-MM-yyyy'} }" />

Would it be possible to directly bind a model dynamically for the pattern contained in a customized model (can be yyyy-MM-dd, dd-MM-yyyy, MM-dd-yyyy, MMM, dd yyyy, etc. from the user preference) and not from user location as :

<Text 
    text="{
      path:'HandlingUnitMultipleModel>PlannedDeliveryDate',
      type:'sap.ui.model.type.DateTime',
      formatOptions: { UTC:true, pattern: '{UserModel>/DateFormat}'} }" />

It doesn't work like it, but maybe there is a way to do that? I know there is a possibility to use a formatter but I wished to know if it was another way by binding inside the binging.

Upvotes: 0

Views: 2442

Answers (3)

alexP
alexP

Reputation: 3765

Use sap.ui.model.odata.type.DateTime instead of sap.ui.model.type.DateTime

<Text 
    text="{
      path:'HandlingUnitMultipleModel>PlannedDeliveryDate',
      type:'sap.ui.model.odata.type.DateTime', //New type
      constraints: {
            displayFormat: 'Date', // ... only the date part is used [...] the time zone is UTC...
            nullable: false //if true, the value null is accepted
          } />

Upvotes: 0

York Chen
York Chen

Reputation: 754

UI5 does not support this, but you can implement by yourself

<Text text="{parts: [{path: 'HandlingUnitMultipleModel>PlannedDeliveryDate'}, {path: 'UserModel>/DateFormat'}], formatter: '.formatMyDate'}" />
function formatMyDate(date, format){
   //your formatting logic
}

Upvotes: 1

Roman
Roman

Reputation: 61

Have you tried rather using the DatePicker with ValueFormat-property ?

Upvotes: 0

Related Questions