2

我创建了两个组件 Listcomponent 和 btncomponent.List 组件是初始化数据表的主要组件,btn 组件是用于在操作列中呈现自定义按钮的自定义组件。

我的问题是当我从数据表中删除记录时如何刷新数据表?这是我的代码..请帮帮我!!!

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() {

  }
}
4

0 回答 0