Victor's Blog

Live as if you were to die tomorrow. Learn as if you were to live forever


How to format a datetime column in ng-grid?

I have been playing with ngGrid control these days. Today, I want to format a date column in the grid. After a little bit research, I found it was very easy to do. All you need is put this in the gridOption object in your controller.

    $scope.gridOptions = {
      data: 'mydata',
      enableRowSelection: true,
      multiSelect: false,
      enableColumnResize: true,
      columnDefs: [
        { field: 'startDate', displayName: 'Date', cellFilter: 'date:\'yyyy-MM-dd\'' }]

In the example, I use "yyyy-MM-dd" as format. But you can change that to whatever format you like :).