3

当用户点击它时,我希望能够将一行切换到编辑模式

我曾尝试在 my.component.html 上使用事件userRowSelect

<ng2-smart-table 
  class="class-content"
  [settings]="settings" 
  [source]="source"
  (deleteConfirm)="onDeleteConfirm($event)"
  (editConfirm)="onSaveConfirm($event)"
  (createConfirm)="onCreateConfirm($event)"
  (rowSelect)="onRowSelect($event)"
  (userRowSelect)="onUserRowSelect($event)"
>
</ng2-smart-table> 

然后在 my.component.ts 中:

onUserRowSelect(e) {
    console.log('onUserRowSelect', e);
}

没有成功

4

1 回答 1

2

我遇到了类似的问题,最后我找到了解决方案:

从文档https://akveo.github.io/ng2-smart-table/#/documentation中,有两个事件适合您:rowSelectuserRowSelect

我们首先为我们的表设置一个名称,然后捕获userRowSelect操作:

<ng2-smart-table #table [settings]="settings" [source]="source" (userRowSelect)="switchToEdit($event)">
</ng2-smart-table>

在我们的组件中:

import {ViewChild} from '@angular/core';

...

@ViewChild('table') table: Ng2SmartTableComponent;

...

switchToEdit(event) {
  this.table.grid.getSelectedRows().forEach((row) => {
    this.table.grid.edit(row);
  });
}
于 2018-04-05T08:48:06.947 回答