datetime field, - read as one format but write as another

datetime field, - read as one format but write as another

crush123crush123 Posts: 417Questions: 126Answers: 18
edited May 2018 in Editor

in my datatable instance, i have a moment formatted field rendered from a standard ISO8061 database entry as follows...

' ('+moment(row.members.LastPaymentDate, "YYYY-MM-DD").format("D MMM YYYY")+')'

this displays, (for example) 2017-01-28 as 28 Jan 2017

what i would like to do is format the datetime editor field in the same way, so that 28 Jan 2017 is displayed

if I set the format like this

type:  'datetime',
            opts: {
                format: 'YYYY-MM-DD',
                showClear: true,
                showClose: true
                }

the correct date of 2017-01-28 is displayed, but if i format like this

type:  'datetime',
            opts: {
                format: 'D MMM YYYY',
                showClear: true,
                showClose: true
                }

the wrong date (20 Jan 2017) is displayed

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Answer ✓

    Can you alter the format that the server send to the client? That is the way I would recommend you do it, so the client-side only sees your formatted value.

    At the moment there is no way to format data for display in Editor - it will always use the "raw" value from the data set.

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18
    edited May 2018

    Thanks Allan,

    I did it as you suggested

    if, as you say though "At the moment there is no way to format data for display in Editor - it will always use the "raw" value from the data set."

    is the format option in the datetime field not redundant ?

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Answer ✓

    No, because you need to tell the date time field what format to expect. It isn't a "formatter" (i.e. it doesn't change the value).

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    gotcha, thanks for the clarification

This discussion has been closed.