Date format in ng-grid row template

Ryan Penfold picture Ryan Penfold · Apr 4, 2014 · Viewed 12.2k times · Source

I've created a ng-grid with the following column definitions:

columns: [
  { field: "CompanyPkid", visible: false },
  { field: "CompanyName", visible: false },
  { field: "StartDate", visible: false, cellFilter: "date:'yyyy-MM-dd'" },
  { field: "CompanyId", 
    displayName: "Company ID",
    cellTemplate: "<div class=\"ngCellText\" ng-class=\"col.colIndex()\">"+
                    "<a href=\"Company/Edit/{{row.getProperty('CompanyPkid')}}\">"+
                      "{{row.getProperty(col.field)}}"+
                    "</a><br />"+
                    "{{row.getProperty('CompanyName')}}<br />"+
                    "{{row.getProperty('StartDate')}}"+
                  "</div>",
  }],

One of the columns is an hidden date column.

One of the columns uses a template and includes the value from the hidden date column.

I would like to format the date in the multiline column to yyyy-MM-dd. Is this possible? If so, how?

Answer

Kabb5 picture Kabb5 · Apr 4, 2014

Use the date filter, like this:

{{row.entity.StartDate | date:'yyyy-MM-dd'}}