Announcement

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

    Get date from LigtGrid in specific format

    SmartGWT version 6.0-p20160713

    Hi,

    I would like to know if it is possible to get Date (or DateTime) from ListGrid in some specified format.

    Example (very simplified code - we used same methods but spread through the code):
    Code:
    ListGrid listGrid = new ListGrid();
    ListGridField field = new ListGridField("date", "Date");
    field.setFormat("dd:MM:yyyy");
    listGrid.setFields(field);
    
    ListGridRecord record = new ListGridRecord();
    record.setAttribute("date", value); // value is of time Date
    
    treeGrid.setData(new ListGridRecord[] { record});
    
    String var = treeGrid.getRecord(0).getAttribute("date");
    This assigns "Tue Nov 10 2015 00:00:00 GMT+0100 (Central Europe Daylight Time)" in var,

    I tried other format properties and although appearance in ListGrid is changed based on those properties, i wasnt able to change string returned by getAttribute method.

    Is there any way to specify the requested format of the strings from date columns (set it either on ListGrid, or ListGridField), or is the only way to do it to call getAttributeAsDate("date") (which would require check on type of column and formatting Date afterwards)?

    #2
    Your call is implicitly forcing a toString() since the method returns String. Call getAttributeAsDate() instead to retrieve a Date object.

    Comment


      #3
      Sorry, we missed that you were aware of getAttributeAsDate(). If you want a one-liner that works for any type of field, use getDefaultFormattedFieldValue()

      Comment

      Working...
      X