This is a migrated thread and some comments may be shown as answers.

Sorting by date

1 Answer 460 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 17 May 2012, 05:22 PM
I would like to sort my datasource by date.  However, whenever I change the field type from "string" to "date" I get "null" in place of the dates.  The format of the dates is:  dd-mm-yy hh:mm

 Can anyone see what I am doing wrong?

var ticketDataSource = new kendo.data.DataSource({
      transport: {
          read: "/support/data",
          dataType: "json",
          create: {
              url:  function() {
                  if (support_create_type == 'new'){
                      var url = "/support/newticketpost/";
                  } else if (support_create_type == 'reply'){
                    var url = "/support/reply/" + support_id + "/";
                  }                          
                   
                  return url;
              },
              type: "POST",
              dataType: "json"                   
          },
          update: {
              url:  function() {
                  if (support_update_type == 'markasread'){
                    var url = "/support/markasread/" + support_id + "/";
                  } else if (support_update_type == 'close'){
                     var url = "/support/close/" + support_id + "/" + support_ticket_closed; 
                  }
                  return url;
              },
              type: "POST",
              dataType: "json"
          },               
      },
     error: function(e) {
        alert(e.responseText);
     },
     sort: { field: "DateCreated", dir: "asc" },
   
      schema: {
        model: {
            id: "ThreadID",
            fields: {
                DateCreated:  { type: "date" },
                Subject:  { type: "string" },
                Closed:  { type: "string" }                    
               }
           }
       }
   });


Many thanks,

1 Answer, 1 is accepted

Sort by
0
Lee
Top achievements
Rank 1
answered on 31 May 2012, 02:33 PM
In answer to this, I needed to define a custom parser and create the dates on the client.
schema: {
    model: {
        id: "foo",
        fields: {
            foo: {type: "number"},
            bar: {type: "date", parse: parseDate}
        }
    }
}

function parseDate(rawDate) {
    //create a valid JavaScript date object from the rawDate string
    return date;   
}
Tags
Data Source
Asked by
Lee
Top achievements
Rank 1
Answers by
Lee
Top achievements
Rank 1
Share this question
or