Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid.dateTimeFomatter modifies value

    Using latest showcase: http://www.smartclient.com/smartclient-latest/showcase/?id=emptyValues Build 2017-06-01

    I've modified the sample below, changes in bold.

    It seems than when using isc.Time.setDefaultDisplayTimezone in combination with datetimeFormatter, the datetimeFormatter doesn't respect the DefaultDisplayTimezone (or maybe ONLY respects it when using datetimeFormatter?). You can see this by enabling/disabling the datetimeFormatter line.

    Code:
    [B]isc.Time.setDefaultDisplayTimezone("00:00");[/B]
    isc.ListGrid.create({
        ID: "countryList",
        width:500, height:224, alternateRecordStyles:true,
        data: countryData,
       [B]// datetimeFormatter: "M/d/yy H:mma",  //<-- If you enable this line, then the VALUE changes as well as the format[/B]
        fields:[
            {name:"countryCode", title:"Flag", width:50, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png", canEdit:false},
            {name:"countryName", title:"Country", [B]width:50[/B]},
            {name:"capital", title:"Capital", [B]width:50[/B]},
            {name:"independence", title:"Nationhood", type:"[B]datetime[/B]", emptyCellValue:"--", [B]width:200[/B]}
        ],
        canEdit:true, editByCell:true, modalEditing:true,
        emptyCellValue: "unknown"
    })
    Is this by design? If so, why would something which is meant to format affect the value? Or is this a bug?

    Edit: The pre-defined values for datetimeFormatter (i.e. toEuropeanShortDatetime, toJapanShortDatetime, toDateStamp, toSerializeableDate) seem to work fine (they don't change the value) so maybe it's just the custom formatting using a FormatString that doesn't work.

    After reading the docs a little more carefully, I see that setting a custom FormatString is not supported for this property (although it sort-of works and it would be really nice if it was supported)

    Custom formatting can also be applied by passing a FormatString instead of a DateDisplayFormat string to DateUtil.setNormalDisplayFormat() et al. See the FormatString docs for details.
    So, it looks like the proper way to get the formatting I want is to use the DateUtil.setNormalDiaplayFormat() method and pass in my format string. So, I tried this:

    Code:
    [B]isc.Time.setDefaultDisplayTimezone("00:00");
    isc.DateUtil.setNormalDisplayFormat("M/d/yy H:mma");
    //isc.DateUtil.setNormalDatetimeDisplayFormat("M/d/yy H:mma");  // <-- this doesn't work either[/B]
    
    isc.ListGrid.create({
        ID: "countryList",
        width:500, height:224, alternateRecordStyles:true,
        data: countryData,
        fields:[
            {name:"countryCode", title:"Flag", width:50, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png", canEdit:false},
            {name:"countryName", title:"Country", [B]width:50[/B]},
            {name:"capital", title:"Capital", [B]width:50[/B]},
            {name:"independence", title:"Nationhood", type:"[B]datetime[/B]", emptyCellValue:"--", [B]width:200[/B]}
        ],
        canEdit:true, editByCell:true, modalEditing:true,
        emptyCellValue: "unknown"
    })
    But the formatting doesn't change from the default. So, what am I doing wrong now?
    Last edited by kylemwhite; 2 Jun 2017, 10:04. Reason: More testing, re-read docs.

    #2
    Use isc.DateUtil.setShortDateTimeDisplayFormat() to affect the formatter used for grids. The "normal" formatter is what's used for DynamicForms and other places where space is at less of a premium.

    Comment


      #3
      I was soooo close. Ok, I tried setShortDateTimeDisplayFormat() and it changes the formatting as expected, great. BUT, it also changes the time value (which was my original problem when I was doing it the wrong way). See code below (modified from http://www.smartclient.com/smartclie...id=emptyValues) :

      Code:
      // Try each of the following, they should be equivalent but the time value changes (unless you're in England?)
      [B]isc.DateUtil.setShortDatetimeDisplayFormat("MM/dd/yyyy HH:mm");
      //isc.DateUtil.setShortDatetimeDisplayFormat("toUSShortDateTime");[/B]
      
      isc.ListGrid.create({
          ID: "countryList",
          width:500, height:224, alternateRecordStyles:true,
          data: countryData,
          fields:[
              {name:"countryCode", title:"Flag", width:50, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png", canEdit:false},
              {name:"countryName", title:"Country", [B]width:50[/B]},
              {name:"capital", title:"Capital", [B]width:50[/B]},
              {name:"independence", title:"Nationhood", type:"[B]datetime[/B]", emptyCellValue:"--", [B]width:200[/B]}
          ],
          canEdit:true, editByCell:true, modalEditing:true,
          emptyCellValue: "unknown"
      });

      Comment


        #4
        Once you've called setDefaultDisplayTimezone(), it stays set for the lifetime of the page. So what you're probably seeing is that you still have a display timezone set from previous tests.

        Comment


          #5
          Well, that's correct... although it doesn't explain the problem.... it explains why I gave a bad example. I forgot to include the setDefaultDisplayTimezone() in my last example and I think it's the combination of setDefaultDisplayTimezone() and using a custom formatter that causes the problem. Try this sample:

          Code:
          [B]isc.Time.setDefaultDisplayTimezone("00:00");
          
          // Try each of the following, they should be equivalent but the time value changes (unless you're in England?)
          isc.DateUtil.setShortDatetimeDisplayFormat("MM/dd/yyyy HH:mm");
          //isc.DateUtil.setShortDatetimeDisplayFormat("toUSShortDateTime");[/B]
          
          isc.ListGrid.create({
              ID: "countryList",
              width:500, height:224, alternateRecordStyles:true,
              data: countryData,
              fields:[
                  {name:"countryCode", title:"Flag", width:50, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png", canEdit:false},
                  {name:"countryName", title:"Country", [B]width:50[/B]},
                  {name:"capital", title:"Capital", [B]width:50[/B]},
                  {name:"independence", title:"Nationhood", type:"[B]datetime[/B]", emptyCellValue:"--", [B]width:200[/B]}
              ],
              canEdit:true, editByCell:true, modalEditing:true,
              emptyCellValue: "unknown"
          });

          Comment


            #6
            What you have now appears to be a data problem. You really have date values, not datetime values - the time values are meaningless. One variation of setting up the formatters is ignoring the time value, one isn't. But the underlying problem is just that you are forcing datetime formatting on values that are really just dates, and have no meaningful time component.

            See the Date and Time Format and Storage overview for more background.

            Comment


              #7
              Hmmm, ok. use the exact same test as above and change one line (for the United States) in the countryData file:

              Code:
                      independence:new Date(1776,6,4[B], 3, 3, 3[/B]),
              Now, we really are using a Date with a meaningful time component and formatting it as a datetime.

              For the first record (United States)

              Using "MM/dd/yyyy HH:mm" I see 07/04/1776 03:03
              Using "toUSShortDateTime" I see 07/04/1776 10:03

              I (and my browser) live in California.
              Last edited by kylemwhite; 3 Jun 2017, 18:52.

              Comment


                #8
                This turned out to be a lack of timezone support in framework method Date.format() - we've added that support for builds dated June 8 and later.

                Comment


                  #9
                  Checked it out on the showcase, looks good. Thanks. I haven't downloaded the latest for my application yet. Will let you know if there are any more issues.

                  Comment

                  Working...
                  X