I have created two component Listcomponent and btncomponent.List component is main component to initilize datatable and btn component is custom component for rendering custom button in action column.
My problem is while i deleting record from data table how can i refresh data table?? Here is my code..please help me out!!!
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Http } from '@angular/http';
import { Ng2SmartTableModule, ViewCell, ServerDataSource } from 'ng2-smart-table';
import { AdminService, AlertService } from '../services/index';
import swal from 'sweetalert2';
import { Constant } from '../helper/constant';
@Component({
template: `
<button class="btn btn-sm btn-info" (click)="onEdit()"><i class="fa fa-pencil-square-o"></i> Edit</button>
<button class="btn btn-sm btn-danger" (click)="onDelete()"><i class="fa fa-trash-o"></i> Delete</button>
`,
})
//render component for custom buttton
export class ActionBtnComponent implements ViewCell, OnInit {
constructor(
private router: Router,
private adminService: AdminService,
private alertService: AlertService) { }
value: string | number;
rowData: any;
ngOnInit() {
}
onEdit() {
this.router.navigate(['/global_admin/edit', this.rowData.id]);
}
onDelete() {
let reqParam = { "user_id": this.rowData.id };
}
}
//Main component for datatable
@Component({
templateUrl: 'list_global_admin.component.html'
})
export class ListGlobalAdminComponent implements OnInit {
constructor(private router: Router, http: Http, constant: Constant) {
this.adminData = new ServerDataSource(http, { endPoint: constant.apiUrl + '/get_admins' });
}
adminData: ServerDataSource;
tblFields = {
columns: {
email: {
title: 'Email'
},
firstname: {
title: 'First Name'
},
lastname: {
title: 'Last Name'
},
actions: {
title: 'Actions',
type: 'custom',
renderComponent: ActionBtnComponent
}
},
mode: 'external',
hideSubHeader: true,
actions: false
};
ngOnInit() {
}
}