简体   繁体   中英

kendo grid date format datasource

I have a kendo grid with a date column. In order to format the date, I'm using: format: {0: dd/MM/yyyy } .

All is well, until I try updating the data source of the grid:

                    chargesDS.data(ko.toJS(newValue));
                    chargesDS.sync();
                    chargesGrid.refresh();

the .data() call (first line) breaks the date column, causing the format to go back to some default format.

Is there a way to refresh the grid so that the dates are displayed properly again?

For anyone who ends up here: I got around the problem by using a template:

function KendoDateTemplate (dateFormat, propertyName) {
    var temp =
        "#= " + propertyName + " ?" + //is the date non-null? if yes, parse. If no, show empty string. 
        "kendo.toString(kendo.parseDate(moment(" + propertyName + ").toDate(), 'yyyy-MM-dd'), '" + dateFormat + "' ) " +
        " : \"\" #"; //second half of tertiary exp

    return temp;
};

...and in the grid options:

{
    field: "DateField", title: "Date",
    template: KendoDateTemplate('MM/dd/yyyy', 'DateField')
}, ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM