简体   繁体   中英

Table column formatting for EDM.Time

I have a table control in linked to a backend OData service. One of the column contains the value "Start time" which is coming from backend as PT01H15M32S . Is there any way that I can convert this format to the legible format? Below is how I am trying to achieve it.

oTable.addColumn(new sap.ui.table.Column({
  label: new sap.ui.commons.Label({text: "Start Time"}),
  template: new sap.ui.commons.TextView().bindProperty("text", {
    path: "STRTTIME",
    type: new sap.ui.model.type.Time({
      source: {
        __edmtype: "Edm.Time"
      },
      pattern: "HH:MM:SS"
    })
  }),
  sortProperty: "STRTTIME",
  editable: false,
}));

There is also a function formatValue for sap.ui.model.type.Time , but I am not sure how can I use it to get the correct time format.

By using types you don't need to call formatValue as the runtime will do this for you. However, you should use the correct type: sap.ui.model.odata.type.Time ! The type you are using does not support EDM data types. Also your coding looks strange.

oTable.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "Start Time"}),
    template: new sap.ui.commons.TextView({
          "text" : { 
              path : "{STRTTIME}",
              type: new sap.ui.model.odata.type.Time({
                  source : { __edmtype: "Edm.Time" }, pattern: "HH:MM:SS" })
              })
           }
    }),
    sortProperty: "STRTTIME",
    editable: false,
}));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM