ng2-smart-table从自定义渲染组件重新加载

时间:2018-02-27 10:19:04

标签: angular ng2-smart-table

我创建了两个组件Listcomponent和btncomponent.List组件是initilize datatable的主要组件,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() {

  }
}

0 个答案:

没有答案