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

    Display an Instant field in grid

    I have a datasource that looks like

    <DataSource ID="myDS" requiresAuthentication="true">
            <field name="myInstant" type="datetime" />
    and my grid is using that datasource.
    In Java, `myInstant` is an `Instant` type. But when the value is rendered in browsers, it shows "Object object"

    How can I show date just like datetime type?

    Please read the Date and Time Format and Storage overview.

    If that doesn't answer your question, please read the FAQ and Debugging overview, and post enough information to allow people to respond usefully.


      Im in no mood to read docs at this time. I know this is a stupid question but my brain is dead.
      I changed field to

       <field name="myInstant" type="datetime" dateFormatter="toUSShortDateTime"/>
      Still no change.


        Sorry you're having a bad day, but there is no actionable information in your post. The docs we linked will explain what's expected.


          Alright. I assume the link you are referring to is this.

          I read the '"datetime" handling' section in that link and also the troubleshooting notes at the end. None of those are helpful.
          "datetime" field shows up as an object with nanoSeconds (in console.log() and the browser response from dev console).

          updatedDateTime: new Date(1609953819000), // Timestamp instance
          anotherDateTime: {nano: 0, epochSecond: 1579022640}, // Instant instance
          I can convert nanoSeconds to datetime in browser (by hardcoding timezone info but I dont want to go down this route). Im expecting Instant should work just like Timestamp and the formatting should be done on server.


            Support for automatic serialization of Instant and other Java8 types was patched into 12.1 and is part of 13.0.

            In other versions, you would have to convert to DateTime or use one of the other strategies listed here:


            Note also that new Date(epochMS) preserves the UTC time being transferred - no information is lost.


              I dont want to go with options listed in the link.

              So I made it simple in my js by doing

              formatCellValue: function (value, record) {
                  if (value.epochSecond) {
                      return new Date(value.epochSecond*1000);
                  return "Invalid DateTime Format";
              That showed me date in the format I wanted.
              But now I cannot filter on that field.

              How can I add a custom filter?


                The correct approach is to transform at the DataSource level via either DataSource.transformResponse() or DataSourceField.getFieldValue(). Otherwise you would need to make sort, filter, editing and other functions work with your custom object - big project and unnecessary.


                  I just changed Instant to Timestamp in fetch() method of my datasource. This means new, redundant fields in my class just for this purpose. But I'll have to live with this for now.


                    Out of curiosity, my datasource in jsp is

                    <isomorphic:loadDS ID="DS_ID"/>
                    I have an xml in backend that DS_ID maps to.

                    How can one use DataSource.transformResponse() or DataSourceField.getFieldValue() with such a datasource?


                      Use addMethods() to add transformResponse to the DS instance. Methods can also be expressed directly in the .ds.xml file if you prefer - see the Component XML overview.

                      Your approach of an extra field is pretty much the worst possible approach, and definitely not something to "live with"! We've given you several better approaches.


                        Yeah. Sorry but none of your options are making any sense. This is first time Im hearing about addMethods(). Is there an example I can follow? I read the documentation for addMethods(). Didnt follow a single word.

                        What is Component XML overview? How is that related to Data source?

                        FYI, Im not a pro in Smartclient.