Следуйте моему подходу: Сначала я создал компонент настраиваемого действия:
[...]
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { ViewCell } from 'ng2-smart-table';
@Component({
selector: 'ngx-custom-actions',
template: `
<div class="btn-group btn-group-sm" role="group">
<button (click)="doEdit()"
nbButton
outline
status="info"
size="small"
[disabled]="!isEditable"
class="mr-2">
Editar
</button>
<button (click)="doDelete()"
nbButton
outline
status="danger"
[disabled]="!isEditable"
size="small">
Excluir
</button>
</div>
`,
})
export class CustomActionsComponent implements ViewCell, OnInit {
isEditable: boolean;
@Input() value: string | number;
@Input() rowData: any;
@Output() edit: EventEmitter<any> = new EventEmitter();
@Output() delete: EventEmitter<any> = new EventEmitter();
ngOnInit() {
this.isEditable = this.value === 'Draft';
}
doEdit() {
this.edit.emit(this.rowData);
}
doDelete() {
this.delete.emit(this.rowData);
}
}
Зарегистрируйтесь в модуле и зарегистрируйтесь в entryComponents!
@NgModule({
declarations: [FormsEngineListComponent, CustomActionsComponent],
imports: [
// others imports
Ng2SmartTableModule,
],
entryComponents: [
CustomActionsComponent,
],
})
export class FormsEngineModule { }
Используйте свою конфигурацию на смарт-таблице ng2
list.component.ts
settings = {
actions: false,
hideSubHeader: true,
columns: {
id: {
title: 'ID',
type: 'number',
},
actions: {
title: 'Ações',
type: 'custom',
renderComponent: CustomActionsComponent,
onComponentInitFunction(instance) {
instance.edit.subscribe(row => {
console.log('edit', row);
});
instance.delete.subscribe(row => {
console.log('delete', row);
});
},
}
},
};
demoData = [
{id: '122323', actions: 'Draft'},
{id: '2342342', actions: 'Ready'},
];
ngOnInit() {
this.source.load(this.demoData);
}