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

Specifying field type as 'date' produces weird formatting

3 Answers 285 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Computer
Top achievements
Rank 1
Computer asked on 15 Jan 2014, 12:03 AM
I have the following Data Source in my page:

var dsAll = new kendo.data.DataSource({
    serverFiltering: true,
    transport: {
        read: {
            type: 'POST',
            url: '/pages/ajax/page.ashx',
            dataType: 'json',
            data: {
                action: 'model',
                modelname: function () {
                    return $('#txtModelName').val()
                }
            },
            cache: false
        }
    },
    schema: {
        data: function (response) {
            if (response == undefined) {
                $('#spanDateRange').hide();
                $('#gridTrend').hide();
            }
            else {
                console.log('DataSource "dsAll" Bound');
                $('#spanDateRange').show();
                $('#gridTrend').show();
                return response;
            }
        },
        model: {
            fields: {
                TrendModelId: { type: 'number' },
                EOM: { type: 'date' },
                Seg: { type: 'string' },
                LostPriceQty: { type: 'number' },
                LostPriceRev: { type: 'number' },
                LostAvailQty: { type: 'number' },
                LostAvailRev: { type: 'number' }
            }
        }
    }
});
The date is passed to the Data Source in this format '2009-12-31T00:00:00'.

But when I bind to a grid or dropdownlist, the format is a weird 'Thu Dec 31 00:00:00 PST 2009'. Strangely enough, creating a template and using kendo.toString(EOM, "d") does produce '12/31/2009'.  If I bind a dropdownlist to the Data Source the selected value is returned in the weird format, even if I define a valuetemplate.

I need the to date to be in some valid format and I'm not sure how to fix it.


Edit:
Ok after further testing I found that the strange formatting only occurs with IE. But I'm still trying to figure out why the value is returned in that format, rather than in the format I specifiy in the valuetemplate.



3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 16 Jan 2014, 03:52 PM
Hi Sean,

I tried to reproduce the problem here but to no avail – everything is working as expected on our side. Could you please check the example and let me know how my setup differs from yours?
Regarding your other question - this is the standard formatting IE is using for Date objects.

Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Computer
Top achievements
Rank 1
answered on 21 Jan 2014, 01:26 AM
Alexander, thank you for your reply.

I modified your example a bit to show what my issue is.  I added a valuetemplate so that what is selected matches what's displayed in the dropdownlist.

The question I have is in regards to getting the selected value in the format that is actually displayed. If you change the selected value you'll see that the alert shows the date object formatting, not the template formatting.

http://jsbin.com/uSadESOy/2/
0
Alexander Popov
Telerik team
answered on 21 Jan 2014, 10:59 AM
Hi Sean,

Basically both template and valueTemplate do not affect the actual data, they are used only for modifying what the user sees. Since the EOM field is of type date the DropDownList will always have a Date object value, so the formatting should be done afterwards. Alternatively, you could specify the EOM field as string and use a parse function that formats the incoming data, although I wouldn't recommend passing date values as strings. Here is an example: 
model: {
  fields: {
    EOM: { type: 'string', parse: function(e){return kendo.toString(kendo.parseDate(e), "g")}  }
  }


Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Computer
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Computer
Top achievements
Rank 1
Share this question
or