-
Notifications
You must be signed in to change notification settings - Fork 35
/
custom-row-action-demo.component.ts
executable file
·46 lines (41 loc) · 1.59 KB
/
custom-row-action-demo.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { CdtSettings, DataManager, CrudTableComponent } from 'ng-mazdik-lib';
import { DemoService } from './demo.service';
import { getColumnsPlayers } from './columns';
@Component({
selector: 'app-custom-row-action-demo',
template: `<app-crud-table #cdt [dataManager]="dataManager"></app-crud-table>`
})
export class CustomRowActionDemoComponent implements AfterViewInit {
dataManager: DataManager;
settings: CdtSettings = new CdtSettings({
crud: true
});
@ViewChild('cdt', { static: false }) cdt: CrudTableComponent;
constructor(private service: DemoService) {
const columns = getColumnsPlayers();
this.dataManager = new DataManager(columns, this.settings, this.service);
}
ngAfterViewInit(): void {
const menuIndex = this.cdt.actionMenu.findIndex(x => x.id === this.dataManager.messages.delete);
const oldBeforeOpen = this.cdt.rowMenuBeforeOpen;
// disable menu based on data
this.cdt.rowMenuBeforeOpen = (row) => {
oldBeforeOpen.bind(this.cdt, row)(); // extend a function
this.cdt.actionMenu[menuIndex].disabled = (row['race'] !== 'ASMODIANS');
};
// custom delete action
this.cdt.actionMenu[menuIndex].command = (row) => {
if (row['race'] === 'ASMODIANS') {
return confirm('Delete row ?') ? this.dataManager.delete(row) : null;
}
};
this.cdt.actionMenu[menuIndex].label = 'custom delete action';
// add new menu
this.cdt.actionMenu.push({
id: 'test',
label: 'new menu',
command: (row) => alert(row['race']),
});
}
}