New to Kendo UI for Angular? Start a free 30-day trial

TreeList Dates Are Treated As Strings in Data Operations

Environment

ProductProgress® Kendo UI® for Angular TreeList

Description

During sorting, filtering, or editing, the dates in the Kendo UI for Angular TreeList are not properly formatted and are treated as strings.

Cause

When the TreeList data contains dates, they need to be instances of the JavaScript Date object. This ensures that dates are handled correctly during formatting, sorting, filtering, and editing.

Solution

If the data that is coming from a remote server is serialized, or if for unspecified reasons the data contains string representations of dates instead of actual JavaScript Date objects, map the data so that each date property has a JavaScript Date as its value.

    private fetch(action: string = '', data?: any, id?: any): Observable<Employee[]> {
        let params = new HttpParams();

        if (typeof id !== 'undefined') {
            params = params.set('id', id);
        }

        if (data) {
            params = params.set('models', JSON.stringify([data]));
        }

        return this.http.jsonp<Employee[]>(
            `https://demos.telerik.com/kendo-ui/service/EmployeeDirectory/${action}?${params.toString()}`,
            'callback'
        ).pipe(tap(response =>
            response.forEach(item =>
                item.HiredDate = new Date(item.HiredDate)
            )
        ));
    }

In this article

Not finding the help you need?