Date format does not work

Posted by: akhabarov on 14 February 2020, 11:01 am EST

  • Posted 14 February 2020, 11:01 am EST

    Hello,
    Can you help me please what i'm doing wrong with data format?

    Html:
    <wj-flex-grid #samplesFlex [itemsSource]="data" (initialized)="initGrid(samplesFlex)" (pastingCell)="pastingFlex(samplesFlex, $event)"
    (copied)="copiedFlex(samplesFlex, $event)">
    <wj-flex-grid-column *ngFor="let col of sampleColumns" [binding]="col.binding" [header]="col.header" [visible]="col.visible"
    [format]="col.format"></wj-flex-grid-column>
    </wj-flex-grid>
    sampleColumns filled as: { header: this.resource.strings.DateTimeSampled, binding: "sampledDate", visible: true, dataType: DataType.Date, format: "'g'" },

    itemsSource: this.data = new CollectionView(this.samplesData.samples);
    samples defined as: public samples: Sample[] = [new Sample];
    where Sample has getter defined as: public get sampledDate(): Date { ...

    But I'm gettin unformated date. What I'm missing?
  • Replied 16 February 2020, 5:18 pm EST

    Hi Andrei,

    It seems that the data is returned in JSON format. The JSON data stores the date in the string format. Therefore, when this data is assigned to the FlexGrid, it does not know that the given key contains dates instead of a string.

    To solve this issue, you will need to parse the date before assigning it as the source of the grid. Please refer to the sample link below for reference:

    https://www.grapecity.com/wijmo/demos/Core/CollectionView/LoadingData/LoadingJSONDates/angular

    Regards,
    Ashwin
  • Replied 19 February 2020, 9:50 am EST

    Thanks for the answer. But in WjFlexGridColumn there is property dataType.
    I would expect it to set dataType for the field.

    In docs written:
    dataType: DataType
    Gets or sets the type of value stored in the column or row.
    Values are coerced into the proper type when editing the grid.

    But seems like it's doing nothing for display?
  • Replied 19 February 2020, 2:28 pm EST

    Hi Andrei,

    As written in the documentation, the dataType property is only used for coercing the data entered in that particular column after editing.
    This means that when you will edit the column, then only it will check whether the entered value can be parsed into the provided dataType and cancels the value accordingly.
    The values are not displayed according to the dataType because they are formatted according to the format applied on that column.

    I hope this clears your doubts.

    ~regards
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels