Search code examples
asp.netkendo-gridkendo-asp.net-mvc

can't change DateTime format kendo grid from 2022-12-12T00:00:00 to 12/12/2022


i have TGL_MASUK as DateTime type on datasource, but the output is 2022-12-12T00:00:00, i want to change the output to dd/MM/yyyy.

$("#grid").kendoGrid({
        dataSource: settingModel.ds_grid_dataSource,
        resizable: "true",
        editable: "inline",
        scrollable: "true",
        sortable: "true",
        filterable: "true",
        pageable: "true",
        height: "500px",
        columns: [
            { field: 'NRP', title: 'NRP', width: 30 },
            { field: 'NAMA', title: 'Name', width: 70 },
            { field: 'SUBCONT_CODE', title: 'Subcont', width: 50 },
            { field: 'DISTRICT', title: 'District', width: 50 },
            { field: 'TGL_MASUK', title: 'Tanggal Masuk', format: "{0:dd/MM/yyyy}", width: 50 }, //this is the column that i want to change format
            
        ]
    }).data("kendoGrid");

can you guys help me, please?


Solution

  • You can use the template field and then kendo.toString() to convert the date to the desired format. This way it should work:

    { field: 'TGL_MASUK', title: 'Tanggal Masuk', template: '#= kendo.toString(TGL_MASUK, "dd/MM/yyyy") #', width: 50 }