This repository was archived by the owner on Feb 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 490
Add support for using Angular pipes to transform data #1494
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d4dc43c
feat: Add support for using Angular pipes to transform data
shanmukhateja 1718e7e
fix: changes as per review
shanmukhateja a174da2
fix: workaround for spread operator as it triggers rollup's 'this is …
shanmukhateja 0d28c6a
fix: rename snippet class name and selector
shanmukhateja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<div class="section banner"> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col s12 m9"> | ||
<h1 class="header center-on-small-only">Using Angular Pipes</h1> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col s12 m9 l12"> | ||
<div class="section"> | ||
<p class="caption"> | ||
You can use Angular Pipe to transform data on the table. | ||
</p> | ||
<div class="col s12 m9 l12 showcase-tabs"> | ||
<ul class="anchor-links"> | ||
<li class="col s4"><a class="waves-effect btn" href="#preview">Preview</a></li> | ||
<li class="col s4"><a class="waves-effect btn" href="#html">HTML</a></li> | ||
<li class="col s3"><a class="waves-effect btn" href="#ts">Typescript</a></li> | ||
</ul> | ||
</div> | ||
<div id="preview" class="col s12 m9 l12"> | ||
<h4 class="header">Preview</h4> | ||
<table datatable [dtOptions]="dtOptions" class="row-border hover"></table> | ||
</div> | ||
</div> | ||
<app-using-pipe-snippet></app-using-pipe-snippet> | ||
</div> | ||
</div> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { UpperCasePipe } from '@angular/common'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ADTSettings } from 'angular-datatables/src/models/settings'; | ||
|
||
@Component({ | ||
selector: 'app-using-ng-pipe', | ||
templateUrl: './using-ng-pipe.component.html' | ||
}) | ||
export class UsingNgPipeComponent implements OnInit { | ||
|
||
constructor( | ||
private pipeInstance: UpperCasePipe | ||
) { } | ||
|
||
dtOptions: ADTSettings = {} | ||
|
||
ngOnInit(): void { | ||
|
||
this.dtOptions = { | ||
ajax: 'data/data.json', | ||
columns: [ | ||
{ | ||
title: 'ID', | ||
data: 'id' | ||
}, | ||
{ | ||
title: 'First name', | ||
data: 'firstName', | ||
ngPipeInstance: this.pipeInstance | ||
}, | ||
{ | ||
title: 'Last name', | ||
data: 'lastName', | ||
ngPipeInstance: this.pipeInstance | ||
} | ||
] | ||
} | ||
l-lin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
l-lin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Component({ | ||
selector: 'app-using-pipe-snippet', | ||
template: ` | ||
<div id="html" class="col s12 m9 l12"> | ||
<h4 class="header">HTML</h4> | ||
<section [innerHTML]="htmlSnippet" hljsContent=".xml"></section> | ||
</div> | ||
<div id="ts" class="col s12 m9 l12"> | ||
<h4 class="header">Typescript</h4> | ||
<section [innerHTML]="tsSnippet" hljsContent=".typescript"></section> | ||
</div> | ||
` | ||
}) | ||
export class UsingPipeSnippetComponent implements OnInit { | ||
|
||
constructor() { } | ||
|
||
htmlSnippet = ` | ||
<pre> | ||
<code class="xml highlight"> | ||
<table datatable [dtOptions]="dtOptions" class="row-border hover"></table></code> | ||
</pre> | ||
`; | ||
|
||
tsSnippet = ` | ||
<pre> | ||
<code class="typescript highlight"> | ||
import { UpperCasePipe } from '@angular/common'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ADTSettings } from 'angular-datatables/src/models/settings'; | ||
|
||
@Component({ | ||
selector: 'app-using-ng-pipe', | ||
templateUrl: './using-ng-pipe.component.html' | ||
}) | ||
export class UsingNgPipeComponent implements OnInit { | ||
|
||
constructor( | ||
private pipeInstance: UpperCasePipe // inject your Angular Pipe | ||
) { } | ||
|
||
// Use ADTSettings instead of DataTables.Settings | ||
dtOptions: ADTSettings = {}; | ||
|
||
ngOnInit(): void { | ||
|
||
this.dtOptions = { | ||
ajax: 'data/data.json', | ||
columns: [ | ||
{ | ||
title: 'ID', | ||
data: 'id' | ||
}, | ||
{ | ||
title: 'First name', | ||
data: 'firstName', | ||
ngPipeInstance: this.pipeInstance // <-- Pipe is used here | ||
}, | ||
{ | ||
title: 'Last name', | ||
data: 'lastName', | ||
ngPipeInstance: this.pipeInstance // <-- Pipe is used here | ||
} | ||
] | ||
}; | ||
} | ||
|
||
} | ||
</code> | ||
</pre> | ||
`; | ||
|
||
ngOnInit(): void { | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { PipeTransform } from '@angular/core'; | ||
|
||
export interface ADTSettings extends DataTables.Settings { | ||
columns?: ADTColumns[]; | ||
} | ||
export interface ADTColumns extends DataTables.ColumnSettings { | ||
/** Set instance of Angular pipe to transform the data of particular column */ | ||
ngPipeInstance?: PipeTransform; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.