-1

How can I globally override the dateformat used by intl and devextreme? Currently, it has correctly loaded the locale de-DE and formats the date like so: d.m.yyyy. However, I'd like to display it dd.mm.yyyy (2-digit for day and month).

Can the default Intl.DateTimeFormat be somehow overwritten? I'm using angular with angular-cli@6.0.0

Regargs
Gabriel

gabs
  • 131
  • 1
  • 11

3 Answers3

0

In Angular, you can set your locale. Please read Internationalization (i18n) in Angular instructions. There you can find step by step instructions on how to set your locale. By using pipes, you can set date format to your desire.

Joe Belladonna
  • 1,349
  • 14
  • 20
  • He is asking about a library that is using its own formatting and localization logic not about angular in general – Mina May 18 '20 at 17:46
0

One solution is to create an overload for each grid. For now it is the only way I found, but I don't like it much, because it is called for each row-column in a grid:

import DataGrid from 'devextreme/ui/data_grid';

export class DevextremeUtils {

  public static registerComponentsDefaultOtions(){
    DataGrid.defaultOptions({
      options: {
        customizeColumns: function(ev){
          for(let i = 0; i < ev.length; i++){
            if(ev[i].dataType == 'date' && ev[i].format == 'shortDateShortTime'){
              ev[i].format = {
                year: "numeric",
                  month: "2-digit",
                  day: "2-digit"
              }
            }
          }
        },
      }
    })
  }

}
Franki1986
  • 1,320
  • 1
  • 15
  • 40
0

It can be overwritten but for each widget as far as I know. You can export a constant containing the intl formatting options and use it with all your widgets.

export const format = { year: 'numeric', month: '2-digit', day: '2-digit' };

That would make all formats regardless of the locale use 2 digits day, 2 digits month, and 4 digits year. Most of DevExtreme widgets if not all have a configuration that would take a format object.

Reference: https://js.devexpress.com/Documentation/ApiReference/Common/Object_Structures/format/

Mina
  • 135
  • 10