question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Format pipe for columns

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[X] feature request
[ ] support request => Please do not submit support request here

Current behavior Data must be formatted before being introduced to the table

Expected behavior It would be helpful if we were able to pass in a format string / function to a column for formatting purposes.

What is the motivation / use case for changing the behavior? I have a lot of columns that have dates stored in ISO 8601 format (which is great for data, but not so much for humans), and it would be great if the table could format the data as it’s rendering.

  • Table version: 0.7.x 4.1.0

  • Angular version: 2.0.x 2.4.1

  • Language: [all | TypeScript X.X | ES6/7 | ES5] Typescript

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:24 (3 by maintainers)

github_iconTop GitHub Comments

45reactions
sincraianulcommented, Jun 28, 2017

@ganeshkantu, you could do something like this:

class DateOnlyPipe extends DatePipe {
  public transform(value): any {
    return super.transform(value, 'MM/dd/y');
  }
}

const columns = [{
  name: 'Date',
  prop: 'dateReported',
  pipe: new DateOnlyPipe('en-US')
}];
17reactions
ghostcommented, May 5, 2017

@SauceCode84 No magic in the rest of the stuff. Its the standard ngx-datatable template but here you go:

Three things in this code below:

  1. To change column names - let-column
  2. Formatting cell content (ex: Date) - let-value
  3. Formatting with multiple properties Ex: Date - let-row
    <ngx-datatable class="material striped" 
                             [rows]="addresses" 
                            [columnMode]="'force'" 
                            [headerHeight]="50" 
                            [footerHeight]="0" 
                            [rowHeight]="50" 
                            [scrollbarV]="true" 
                            [scrollbarH]="true">
        <ngx-datatable-column prop="createdDate" [width]="120">
            <ng-template let-column="column" ngx-datatable-header-template>
                Since
            </ng-template>
            <ng-template let-value="value" ngx-datatable-cell-template>
                {{value | date: 'MM/dd/yyyy'}}
            </ng-template>
        </ngx-datatable-column>
       <!-- Rest of the columns -->
        <ngx-datatable-column>
            <ng-template let-column="column" ngx-datatable-header-template>
                Location
            </ng-template>
            <ng-template let-row="row" ngx-datatable-cell-template>
                {{row.addressLine1}} {{row.city}},{{row.state}} {{row.zipcode}}
            </ng-template>
        </ngx-datatable-column>
    </ngx-datatable>

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Date Pipes for some columns in PrimeNG table ...
I want to format that fields using a date pipe. html file <ng-template pTemplate="body" let-rowData let-columns="columns ...
Read more >
Formatting Data using Pipes in the Ignite UI for Angular Grid
We are setting the autoGenerate property to true; do to this, Ignite UI will auto-generate all the columns by reading from the data...
Read more >
shell - format to columns for real-time data (pipe)
I am looking for a way how to do a similar thing that column -t does, but without waiting for the input to...
Read more >
Enhance your Angular Grid reports with Formatted values and ...
When we know which columns contain dates we can format them with the pipe transform method. From the docs: “A valueFormatter allows you...
Read more >
Enhance your Angular Grid with Formatted values and Links
In our example, the column is named 'releaseDate'. When we know which columns contain dates we can format them with the pipe transform ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found