akveo / ng2-smart-table

Angular Smart Data Table component
https://akveo.github.io/ng2-smart-table/
MIT License
1.63k stars 876 forks source link

Custom Button Action #750

Closed miguelleitevieira closed 6 years ago

miguelleitevieira commented 6 years ago

Hi,

I created a custom button column on my table.

button: { title: null, type: 'custom', renderComponent: ButtonRenderComponent, defaultValue: null, editor: { type: 'custom', component: ButtonRenderComponent, }, },

import { Component, Input, OnInit } from '@angular/core'; import { ViewCell } from 'ng2-smart-table'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { TranslateService } from '@ngx-translate/core';

@Component({ template: <button class="btn" [disabled]="object.disabled" [ngClass]="object.style" (click)="this.object.action()">{{object.name}}</button>, })

export class ButtonRenderComponent implements OnInit { public object; @Input() value;

constructor() {
}

ngOnInit() {
    this.object = this.value;
}

}

And on the data object I'm setting some button configurations;

button: { name: this.translate.instant('TAG_BTN_CANCEL_DOWNGRADE'), style: "btn-danger", action: this.onCancelDowngrade, disabled: true, }

I want to call the function onCancelDowngrade when the user click on button. But the button don't recognize the function.

I need a thing like a event that trigger this function on main component.

Someone did this?

Thanks.

miguelleitevieira commented 6 years ago

I'm trying to use EventEmitter. I create the emit on button and add this: <ng2-smart-table [settings]="pricePlanSettings" [source]="pricePlanSource" (test)="test($event)"> But the event isn't catch. Some help?

orpuig commented 6 years ago

You solved it???? what happened? I could make use of the solution.