Announcement

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

    Getting date attribute from ListGrid's record

    Hi,

    we're using SmartGWT version 2.5 and have there following problem:
    There is a listgrid with one column of date type and have assigned datasource with 1 date field, datesource extends RestDataSource and uses server for retrieving data.
    When data are fetch and I call getRecords()[0].getAttributeAsDate("date"), error occurs and when I call only getAttribute("date") string value is get instead of serialized date.
    When data are set from client and set record in data contains attribute "date" as object Date, getAttribute and getAttributeAsDate return correct value

    ListGrid:
    Code:
    public class TestDateGrid extends ListGrid {
    
    	public TestDateGrid() {
    		RestDataSource ds = new RestDataSource();
    		ds.setID("TESTDS");
    		DataSourceDateField dateField = new DataSourceDateField("date", "DATE");
    		ds.setFields(dateField);
    
    		this.setDataSource(ds);
    	}
    }
    [CODE]
    TestDateGrid dateGrid = new TestDateGrid();
    dateGrid.fetchData();
    dateGrid.getRecord(0).getAttributeAsDate("date"); // exception is thrown - ret.getTime is not a function
    [CODE]

    response from server:
    Code:
    {
        "response": {
            "totalRows": 1,
            "data": [
                {
                    "date": "2011-09-30"
                }
            ],
            "status": 0,
            "startRow": 0,
            "endRow": 1
        }
    }
    Can you please advice me what we're doing wrong? This issue is quite urgent for us.

    thanks

    #2
    fetchData() is asynchronous. The data will be present when the DataArrived event fires.

    Comment


      #3
      thanks for answer, maybe I wrote that accurate, we're trying to get attribute from record after clicking on record, so the problem is not that we don't have already record data but when I take record and then call getAttributeAsDate("date") on such record I retrieve error and when I call getAttribute("date"), string value is returned.
      Problem is that server responses in format "DD-MM-YYYY" (as in showcase) and this value is not transfered to date object.

      I tried to use DateUtil.setDateParser but this parser is never called.

      What am I doing not correct?

      thanks

      Comment


        #4
        The expected response format is yyyy-mm-dd (XML Schema date format, as doc'd). You seem to be already providing that format but then you just wrote now that you're using a different format. Regardless, if you cannot make your server output the expected format, use a FiedValueParser on the DataSource to fix the problem. DateUtil configures formats for user-entered data, not data from the server.

        Your previous test case was wrong (because fetchData() is asynchronous). If you have new sample code, show it.

        Comment


          #5
          I tried any format of date also in 'yyyy-mm-dd' format but the problem still remains.

          to summarize, the whole scenario is following:
          1. create rest datasource with date field item with name "date"
          2. create list grid that uses datasource from 1.
          3. fetch data, fetched data contains 1 record with 1 property "date" valued "2000-07-04"
          4. on record click we want to get "date" property of clicked record as a date object and do some logic there

          Problem is that when we use event.getRecord().getAttributeAsDate("date") there is error and when event.getRecord().getAttribute("date") is called string "2000-07-04" is returned. I think parsing it into date in our code is not a good solution.

          thanks

          Comment


            #6
            This is very basic functionality with many automated tests showing green. If you really think the problem is in the framework and not in your code, please put together a minimal, runnable test case showing this.

            Comment


              #7
              I think I found out the problem - it seems as problem in our code, when there won't be problem, I'll create sample test project for that,

              thanks for your answers

              Comment

              Working...
              X