Kendo Angular 2 Grid DateTime format

前端 未结 4 822
一个人的身影
一个人的身影 2021-01-13 07:28

Does anyone know how to properly format a DateTime in the grid? (Is this datatype even supported?).

No matter what I put in the \"filter\" property of the column, my

4条回答
  •  旧巷少年郎
    2021-01-13 08:00

    In order for the grid to format the date properly you need to convert it into a JS date. I usually do that in the callback from the ajax call retrieving the data from the server. Something like that:

    api.get('some server url').then(function(data) {
      if (data.SomeDate) data.SomeDate = new Date(data.SomeDate);
    });

    (This is a pseudo code, don't use it directly)

    This will allow you to format the date as:

    field="SomeField" format='{0:d}

    or

    field="SomeField" format='{0:MM/dd/yyyy h:mm a}
    

    Hope that helps.

提交回复
热议问题