forked from akveo/ng2-smart-table
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): add an example with a custom button view
- Loading branch information
Alexander Zhukov
committed
Mar 30, 2017
1 parent
f901e29
commit 8df40c3
Showing
3 changed files
with
116 additions
and
0 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
100 changes: 100 additions & 0 deletions
100
src/app/pages/examples/various/basic-example-button-view.component.ts
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,100 @@ | ||
import { Component, OnInit, Input } from '@angular/core'; | ||
|
||
import { ViewCell } from '../../../../ng2-smart-table'; | ||
|
||
@Component({ | ||
selector: 'button-view', | ||
template: ` | ||
<button (click)="showAlert()">{{ renderValue }}</button> | ||
`, | ||
}) | ||
export class ButtonViewComponent implements ViewCell, OnInit { | ||
renderValue: string; | ||
|
||
@Input() value: string | number; | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
this.renderValue = this.value.toString().toUpperCase(); | ||
} | ||
|
||
showAlert() { | ||
alert(this.renderValue); | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'basic-example-button-view', | ||
template: ` | ||
<ng2-smart-table [settings]="settings" [source]="data"></ng2-smart-table> | ||
`, | ||
}) | ||
export class BasicExampleButtonViewComponent implements OnInit { | ||
|
||
settings = { | ||
columns: { | ||
id: { | ||
title: 'ID', | ||
}, | ||
name: { | ||
title: 'Full Name', | ||
}, | ||
username: { | ||
title: 'User Name', | ||
}, | ||
email: { | ||
title: 'Email', | ||
}, | ||
button: { | ||
title: 'Button', | ||
type: 'custom', | ||
renderComponent: ButtonViewComponent, | ||
}, | ||
}, | ||
}; | ||
|
||
data = [ | ||
{ | ||
id: 1, | ||
name: 'Leanne Graham', | ||
username: 'Bret', | ||
email: '[email protected]', | ||
button: 'Button #1', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Ervin Howell', | ||
username: 'Antonette', | ||
email: '[email protected]', | ||
button: 'Button #2', | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Clementine Bauch', | ||
username: 'Samantha', | ||
email: '[email protected]', | ||
button: 'Button #3', | ||
}, | ||
{ | ||
id: 4, | ||
name: 'Patricia Lebsack', | ||
username: 'Karianne', | ||
email: '[email protected]', | ||
button: 'Button #4', | ||
}, | ||
{ | ||
id: 5, | ||
name: 'Chelsey Dietrich', | ||
username: 'Kamren', | ||
email: '[email protected]', | ||
button: 'Button #5', | ||
}, | ||
]; | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
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