首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ng2-smart-table -如何在其他视图中打开记录

ng2-smart-table -如何在其他视图中打开记录
EN

Stack Overflow用户
提问于 2020-09-04 01:13:11
回答 2查看 351关注 0票数 0

我能够向表中添加自定义操作,但我仍然不知道如何使用该自定义操作在单击时在不同的页面/模式中打开记录。如何将ID分配给该记录行?如何将其传递给不同的视图?

在component.html中

代码语言:javascript
复制
<ng2-smart-table [settings]="settings" [source]="source" (custom)="onCustomAction($event)"></ng2-smart-table>

在component.ts中

代码语言:javascript
复制
settings = {
mode: 'external',
hideSubHeader: true,    
actions: {
  position: 'right',
  add: false,
  edit:false,
  delete: false,
  custom: [
    { name: 'viewRecord', title: '<i class="far fa-file-alt"></i>'},
  ],
},
columns: {
  firstName: {
    title: 'First Name',
    type: 'string',
  },
  lastName: {
    title: 'Last Name',
    type: 'string',
  },
  username: {
    title: 'Username',
    type: 'string',
  },
  email: {
    title: 'E-mail',
    type: 'string',
  },
  age: {
    title: 'Age',
    type: 'number',
  },
},

};

代码语言:javascript
复制
onCustomAction(event): void {
   
//WHAT TO DO HERE?
   
  }
EN

回答 2

Stack Overflow用户

发布于 2020-09-11 05:01:58

已解决的

代码语言:javascript
复制
    onCustomAction(event): void {

        //get action name to switch in case of different actions.
        var actionName = event.action; 

        //get row id.
        var id = event.data.id; 

        //navigate to edit/view url.
        this.router.navigate(url) 
    }
票数 1
EN

Stack Overflow用户

发布于 2020-10-10 21:04:00

您可以在构造器中注入NbdialogService以在对话框/模式中打开

代码语言:javascript
复制
private dialogService: NbDialogService
  onCustomAction(event) {
   switch (event.action) {
     case 'view-details':
        this.service.getDetails(event.data.Id)
         .pipe(
           tap(res => {
           this.dialogService.open(UserDetailsComponent, { // inject your component will be displayed in modal
            context: {
              details: res,
            },
          });
        })
      ).subscribe();
    break;
  default:
    console.log('Not Implemented Action');
    break;
}

或者像使用this.router.navigate(url)那样确保导航

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63728570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档