I am looking to implement a feature where clicking on a row in my table will load a specific component. In order to test this functionality, I have created a simple alert that pops up when a row is clicked displaying the message THIS ROW HAS CLICKED
. This confirms that row clicking is functioning correctly.
However, my ultimate goal is to display the details of the clicked row by opening a separate component. You can view an example of what I'm aiming for in the mockup image below:
https://i.sstatic.net/E67hG.pngThe table implementation shown below is used within the finished
component:
finishing.component.ts
import { Component, OnInit } from '@angular/core';
import { Finished } from './finished.model';
import { FinishedService } from './finished.service';
@Component({
selector: 'ngx-finished',
styles: [],
template: `
<ng2-smart-table
[settings]="settings"
(userRowSelect)="onCustomAction($event)"
[source]="list"
></ng2-smart-table>
`
})
export class FinishedComponent implements OnInit {
list: Finished[] = [];
constructor(private service: FinishedService) {}
ngOnInit() {
this.service.getPatients().subscribe(actionArray => {
let patients_data = actionArray.payload.get('data');
if (patients_data) {
this.list = patients_data;
}
});
}
settings = {
add: {
addButtonContent: '<i class="nb-plus"></i>',
createButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>',
confirmCreate: true
},
edit: {
editButtonContent: '<i class="nb-edit"></i>',
saveButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>',
confirmSave: true
},
delete: {
deleteButtonContent: '<i class="nb-trash"></i>',
confirmDelete: true
},
view: {
viewButtonContent: ''
},
columns: {
nic: {
title: 'NIC'
},
name: {
title: 'Name'
},
address: {
title: 'Address'
},
email: {
title: 'Email'
},
haircolor: {
title: 'Hair Color'
}
}
};
onCustomAction(event) {
alert(`THIS ROW HAS CLICKED`);
}
}
To achieve the desired functionality of loading the relevant component when a row is clicked, I need to make some modifications within the onCustomAction
function:
onCustomAction(event) {
I want to invoke the above mentioned component in here.
}