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

How to bind a date and enable filtering for a field where date is in a format like this > /Date(1368388119000)/

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karandeep Singh
Top achievements
Rank 1
Karandeep Singh asked on 16 May 2013, 09:00 PM
01.<div data-bind="kendoGrid: {
02.    data: $root.Reports,
03.    groupable: true,
04.    scrollable: true,
05.    filterable: true,
06.    sortable: true,
07.    pageable: {
08.        pageSize: 10,
09.        pageSizes: true
10.    },
11.    columns: [
12.                    { field: 'ReportNumber', title : 'Report Number'},
13.                    { field: 'CreateDate', type:'date', template: function(dataItem) { return '<span>' + ConvertDate(dataItem.CreateDate, 'MM/DD/YYYY') + '</span>';}, title: 'Create Date'}
14.                    { command: { text: 'View', click: $root.ShowReport }, title:' ', width: 80}
15.    ]
16.    }">
17.</div>


01.function  ConvertDate(value, format) {
02.            var valueUnwrapped = ko.utils.unwrapObservable(value);
03.            var pattern = format || 'mmmm d, yyyy';
04.            if (valueUnwrapped == undefined || valueUnwrapped == null) {
05.                return '';
06.            } else {
07.                var date = moment(valueUnwrapped);
08.                var str = moment(date).format(pattern);
09.                return str;
10.            }
11.        }
Hi,

I am using knockout-kendo.js 

In the underlying data source for the grid the "CreateDate" is just a string like this: /Date(1368388119000)/
I have been able to display the date in the grid using the template as shown in the code above. But when I try to use the filter on the Create Date field it throws a javascript error  : Uncaught TypeError: Object /Date(1368388119000)/ has no method 'getTime'

What is the proper way to bind the date in this format so that the filtering works with it?

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 May 2013, 05:10 PM
Hello,

Please try with the below link.

http://docs.kendoui.com/getting-started/framework/globalization/dateparsing

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Karandeep Singh
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or