Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

445
Views
Angular 2 Pipe ShortDate on NGX Data Table

I would like to format a date column as a short date in Angular 2 NGX Datatable.

Here is the HTML:

<ngx-datatable
  [rows]="toDos"
  [columns]="columns">
</ngx-datatable>

Here is the component TypeScript

import { Component, OnInit } from '@angular/core';
import { IToDo } from '../shared/todo';
import { ToDoService } from '../shared/todo.service';

@Component({
  selector: 'app-todo-list',
  templateUrl: './todo-list.component.html',
  styleUrls: ['./todo-list.component.css']
})

export class TodoListComponent implements OnInit {

  toDos: IToDo[];
  columns = [
    { prop: 'toDoId' },
    { name: 'To Do', prop: 'name' },
    { prop: 'priority' },
    { prop: 'dueDate'  },
    { prop: 'completed' }
  ];

  constructor(private _toDoService: ToDoService) {
  }

  ngOnInit() {
    this.toDos = this._toDoService.getToDos();
  }
}

I have tried this in the HTML but it gives a template parse error:

<ngx-datatable
  [rows]="toDos"
  [columns]="columns"
      <ngx-datatable-column prop="dueDate">
      <ng-template let-value="value" ngx-datatable-cell-template>
        {{value | date[:shortDate]}}
      </ng-template>
    </ngx-datatable-column>
    >
</ngx-datatable>
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

constructor(
private fb: FormBuilder,
private _currencyPipe: CurrencyPipe,
private _datePipe: DatePipe
) {
this.rows = [
  {from: Date().toString(), to: Date(), amount: 100, verified: false},
  {from: Date(), to: Date(), amount: 100, verified: true},
];
}

ngOnInit() {

this.columns = [
  { name: 'FROM', prop: 'from', pipe: this.datePipe()},
  { name: 'TO', prop: 'to', pipe: this.datePipe()},
  { name: 'AMOUNT', prop: 'amount', width: 85, pipe: this._currencyPipe},
  { name: 'CONFIRM | DELETE', cellTemplate: this.editCell, width: 155}
];
this.buildForm();
}

datePipe () {
return {transform: (value) => this._datePipe.transform(value, 'MM/dd/yyyy')};
}

You can always use the programatic aproach to applying pipes, infact you could create custom pipes with this aproach. The pipe @Input in the ngx-dataTable expects a Pipelike structure with a transform: Function. you could make any function that returns a transform function and manipulate data as you please.

about 4 years ago · Santiago Trujillo Report

0

You can just use date pipe to format value.

{{value | date:'shortDate'}} is equivalent to {{value | date:'ymd'}} which outputs date like following: 22/08/2017

about 4 years ago · Santiago Trujillo Report

0

Hope this will help you

  <ng-template #dateColumn let-row="row" let-value="value" let-i="index">
    {{value | date:'dd-MM-yyyy'}}
  </ng-template>

export class CvbankListComponent implements OnInit {
  @ViewChild('dateColumn') dateColumn: TemplateRef<any>;
    .
    .
    .
    this.columns = [
       .
       .
      { name: 'Date', prop: 'Date', cellTemplate: this.dateColumn },
    ];
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!