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

Autocomplete unable to display the date

1 Answer 64 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 22 Nov 2012, 07:03 AM
I would like to display both description and Date in my kendo auto complete. THe following code will display as expected except the date. The date is displaying weird format 


if i type Nike

xml schmea
<d:SDate  m:type="Edm.DateTime">2012-11-21T18:30:51.097</d:SDate>
it will come up Nike (/Date(13534560000)/)    


 $("#titles").kendoAutoComplete({
                minLength: 3,
                dataTextField: "SDesc",
                dataValueField: "RefID",
                template: '${ data.SDesc } ' + '(' + '<span>${ data.SDate }</span>' + ')',
                                 
                dataSource: {
                    type: "odata",
                    serverFiltering: true,
                    serverPaging: true,
                    pageSize: 20,
                    transport: {
                        read: "http://localhost:54329/HH_WcfDataService.svc/Product"
                    }
                }
            });

1 Answer, 1 is accepted

Sort by
0
Accepted
Burke
Top achievements
Rank 1
answered on 30 Nov 2012, 05:03 PM
Hi Mark!

This is a long standing issue with ASP.NET.  Check out this SO thread.

You can handle it two ways in Kendo UI.  The first way is to parse the date in you template per this thread response from Rosen
template: '${ data.SDesc } ' + '(' + '<span>${ kendo.toString(new Date(parseInt(data.SDate.replace(/[A-Za-z$--/]/g, ""))),"MMMM dd yyyy") }</span>' + ')',
You can also do it in the parse method on the dataSource if you want to keep your template cleaner...
// other data source code omitted for berevity
....
transport: {
  read: "http://localhost:54329/HH_WcfDataService.svc/Product"
},
schema: {
  parse: function(data) {
               
    // loop through the data and format the SDate field
    $.each(data, function() {
      this.SDate = kendo.toString(new Date(parseInt(this.SDate.replace(/[A-Za-z$--/]/g, ""))),"MMMM dd yyyy");
    });
 
    // return the data back
    return data;
  }
}
Cheers!
Tags
AutoComplete
Asked by
Mark
Top achievements
Rank 1
Answers by
Burke
Top achievements
Rank 1
Share this question
or