-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Angular Pipe support for Angular v10
- Loading branch information
1 parent
139c987
commit 3a91262
Showing
8 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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'; | ||
|
||
@Component({ | ||
selector: 'app-using-ng-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 UsingNgPipeSnippetComponent 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 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-ng-pipe-snippet></app-using-ng-pipe-snippet> | ||
</div> | ||
</div> | ||
</div> |
This file contains 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 | ||
} | ||
] | ||
}; | ||
} | ||
|
||
} |
This file contains 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 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 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 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 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; | ||
} |