I think the simplest way to do this would be with a custom component. You can specify a column where the component will be rendered on each row and encapsulate the play/stop behavior in this component.
First, create a custom component, for example MediaControlComponent
:
@Component({
selector: 'ngx-media-control',
template: `<a href="javascript:void(0)" (click)="onClick()">
<i *ngIf="!isPlaying" class="nb-play"></i>
<i *ngIf="isPlaying" class="nb-square"></i></a>`,
})
export class MediaControlComponent implements OnInit {
public isPlaying: boolean;
public renderValue: string;
@Input() value: string | number;
@Input() rowData: any;
@Output() save: EventEmitter<any> = new EventEmitter();
constructor() {
}
ngOnInit() {
this.renderValue = this.value.toString().toUpperCase();
}
onClick() {
this.isPlaying = this.isPlaying ? false : true;
this.save.emit(this.rowData);
}
}
Make sure you add this component in your module, both in imports
and entryComponents
.
Then, in your ng2-smart-table settings, add a column:
mediaControl: {
title: 'mediaControl',
type: 'custom',
renderComponent: MediaControlComponent,
onComponentInitFunction: (instance: any) => {
instance.save.subscribe(row => {
// Do something (you have the row information in the `row` variable).
});
}
},
That's it! You'll have the behavior you want for the play/stop button, as well as a way to make something happen when the play/stop button is clicked.
Note: I am not rendering the custom component in the action
part of ng2-smart-table settings due to it not working when I tried it (I am rendering it in a column instead). If you can make it work, go ahead.