-
Notifications
You must be signed in to change notification settings - Fork 877
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom-actions): add the custom actions feature (#338)
- Loading branch information
Showing
10 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/app/pages/examples/custom-edit-view/basic-example-custom-actions.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,79 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'basic-example-custom-actions', | ||
template: ` | ||
<ng2-smart-table [settings]="settings" [source]="data" (custom)="onCustom($event)"></ng2-smart-table> | ||
`, | ||
}) | ||
export class BasicExampleCustomActionsComponent { | ||
|
||
settings = { | ||
actions: { | ||
add: false, | ||
edit: false, | ||
delete: false, | ||
custom: true | ||
}, | ||
custom: [{ | ||
action: 'view', | ||
buttonContent: `view ` | ||
}, { | ||
action: 'duplicate', | ||
buttonContent: 'duplicate ' | ||
}], | ||
columns: { | ||
id: { | ||
title: 'ID', | ||
}, | ||
name: { | ||
title: 'Full Name', | ||
}, | ||
username: { | ||
title: 'User Name', | ||
}, | ||
email: { | ||
title: 'Email', | ||
} | ||
}, | ||
}; | ||
|
||
data = [ | ||
{ | ||
id: 1, | ||
name: 'Leanne Graham', | ||
username: 'Bret', | ||
email: 'Sincere@april.biz', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Ervin Howell', | ||
username: 'Antonette', | ||
email: 'Shanna@melissa.tv', | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Clementine Bauch', | ||
username: 'Samantha', | ||
email: 'Nathan@yesenia.net', | ||
}, | ||
{ | ||
id: 4, | ||
name: 'Patricia Lebsack', | ||
username: 'Karianne', | ||
email: 'Julianne.OConner@kory.org', | ||
}, | ||
{ | ||
id: 5, | ||
name: 'Chelsey Dietrich', | ||
username: 'Kamren', | ||
email: 'Lucio_Hettinger@annie.ca', | ||
}, | ||
]; | ||
|
||
constructor() { } | ||
|
||
onCustom(event) { | ||
console.log(event); | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
src/ng2-smart-table/components/tbody/cells/custom.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,32 @@ | ||
import { ChangeDetectionStrategy, Component, Input, Output, EventEmitter } from '@angular/core'; | ||
|
||
import { Grid } from '../../../lib/grid'; | ||
import { Row } from '../../../lib/data-set/row'; | ||
|
||
@Component({ | ||
selector: 'ng2-st-tbody-custom', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: ` | ||
<a *ngFor="let custom of grid.getSetting('custom')" href="#" | ||
class="ng2-smart-action ng2-smart-action-custom-custom" [innerHTML]="custom.buttonContent" (click)="onCustom(custom, $event)"></a> | ||
` | ||
}) | ||
export class TbodyCustomComponent { | ||
|
||
@Input() grid: Grid; | ||
@Input() row: Row; | ||
@Input() source: any; | ||
@Output() custom = new EventEmitter<any>(); | ||
|
||
onCustom(custom: any, event: any) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
|
||
this.custom.emit({ | ||
custom: custom, | ||
data: this.row.getData(), | ||
source: this.source | ||
}); | ||
} | ||
|
||
} |
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
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