Problems with 292 Calendar and DataBinding

Using 292 build. Trying to bind a Calendar to a datasource. Using the following code for the Calendar:

		RestDataSource dataSource = new RestDataSource() {
		};
		dataSource.setDataFormat(DSDataFormat.JSON);
		dataSource.setFetchDataURL("List.js");
		DataSourceIntegerField id = new DataSourceIntegerField("eventId");
		id.setPrimaryKey(true);
		dataSource.addField(id);
		dataSource.addField(new DataSourceTextField("name"));
		dataSource.addField(new DataSourceTextField("description"));
		dataSource.addField(new DataSourceDateField("startDate"));
		dataSource.addField(new DataSourceDateField("endDate"));

		calendar.setDataSource(dataSource);
		calendar.setAutoFetchData(true);

		calendar.draw();

List.js content:
[{“startDate”:“2009-02-16 15:30:00”,“name”:“app”,“eventId”:1,“description”:“app”,“endDate”:“2009-02-16 16:30:00”}]

Tried with “status”:0,data:… with same results.

In the console I see the following:
04:27:10.380:XRP8:INFO:RPCManager:rpcResponse(unstructured) results –>"[{“startDate”:“2009-02-16 15:30:00”,“name”:“app”,“eventId”:1,“description”:“app”,“endDate”:“2009-02-16 16:30:00”}]
"<–
04:27:10.676:XRP8:INFO:ResultSet:isc_ResultSet_22 (created by: isc_OID_0):Received 0 records from server
04:27:11.004:XRP8:DEBUG:ResultSet:isc_ResultSet_22 (created by: isc_OID_0):full length set to: 0
04:27:11.332:XRP8:DEBUG:ResultSet:isc_ResultSet_22 (created by: isc_OID_0):integrating 0 rows into cache at position 0
04:27:11.690:XRP8:INFO:ResultSet:isc_ResultSet_22 (created by: isc_OID_0):cached 0 rows, from 0 to 0 (0 total rows, 0 cached)
04:27:12.065:XRP8:INFO:ResultSet:isc_ResultSet_22 (created by: isc_OID_0):Cache for entire DataSource complete

Thanks in advance.

BTW does the status:0,data:… part is mandatory for responses or plain data would be fine when handling the request on the server?

Just to clarify, are you seeing this only with build 292? Was it working for you previously?

That wouldn’t have worked on any build - yes you need the status and data elements shown in the docs for RestDataSource.

Thanks for quick reply!

It’s all working. I’ve used the following helper class to bind the calendar in ASP.NET MVC:

    public static class Helpers
    {
        public static object FormatResponse(this object obj)
        {
            return new { response = new { status = 0, data = obj } };
        }

        public static ActionResult JsonResponse(this Controller controller, object obj)
        {
            return new JsonResult {Data = FormatResponse(obj)};
        }
    }

this would allow to do the following in the controller:

        public ActionResult List()
        {
            return this.JsonResponse(Event.GetTestData());
        }

The Event is defined as follows:

    public class Event
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string StartDate { get; set; }
        public string EndDate { get; set; }

        public static Event[] GetTestData()
        {
            var events = new List<Event>();
            for (int i = 0; i < 3; i++)
            {
                events.Add(new Event
                           {
                               Id = i,
                               Description = i.ToString(),
                               StartDate = new DateTime(2009, 2, 15, 1 + i * 2, 0, 0, DateTimeKind.Utc).ToString("yyyy-MM-dd hh:mm:ss"),//.ToJsConsumableString(),
                               EndDate = new DateTime(2009, 2, 15, 1 + i * 2 + 1, 0, 0, DateTimeKind.Utc).ToString("yyyy-MM-dd hh:mm:ss"),//.ToJsConsumableString(),
                               Title = i.ToString(),
                           });
            }
            return events.ToArray();
        }
    }

The following config code is also needed on the SmartGWT side. Be careful with casing - javascript is case sensitive, so by default Calendar expects fields starting with lowercase: (“name”, “description”, “startDate”, “endDate”):

		DataSourceIntegerField id = new DataSourceIntegerField("Id");
		id.setPrimaryKey(true);
		dataSource.addField(id);
		dataSource.addField(new DataSourceTextField("Title"));
		dataSource.addField(new DataSourceTextField("Description"));
		dataSource.addField(new DataSourceDateField("StartDate"));
		dataSource.addField(new DataSourceDateField("EndDate"));

		calendar.setNameField("Title");
		calendar.setDescriptionField("Description");
		calendar.setStartDateField("StartDate");
		calendar.setEndDateField("EndDate");

This code is taken from my spike, so it just tries to bind to the Calendar at any cost.

Hope this helps.