【问题标题】:HandsonTable event not firingHandsonTable 事件未触发
【发布时间】:2019-01-16 14:54:10
【问题描述】:

我正在使用 Angular 6.1.1 和 HandsonTables 5.0.0

我的热表正在正确显示并填充了数据。我已将一列设置为可编辑,但是当我通过在该列中输入更改值时,afterChange 事件根本没有触发,配置如下所示。

组件 HTML:

<hot-table [hotId]="hotInstance" [settings]="hotSettings"
           [data]="dataset" (afterChange)="onAfterChange($event)"></hot-table>

组件 TS(ngOnInit 和 FetchData 调用正常,编辑 FieldA 时不会引发 onAfterChange):

export class PartsComponent implements OnInit {

dataset: any;
fetched = false;
error = false;
hotInstance: string = 'hot';
user : object = {};

hotSettings = { };

constructor(private route: ActivatedRoute, 
private location: Location, 
private repositoryService: RepositoryService,
private hotRegisterer: HotTableRegisterer,
private auth: AuthService) { 


  const $component = this;

  this.hotSettings = {
    colHeaders: ['System ID', 'Field A', 'Field B.'],
    columns: [
      {
        data: 'Id',
        type: 'numeric',
        readOnly: true
      },
      {
        data: 'FieldA',
        type: 'text',
        readOnly: false
      },
      {
        data: 'FieldB',
        type: 'text',
        readOnly: true
      }
    ],
    allowInsertColumn: false,
    allowRemoveColumn: false,
    selectionMode: 'single',
    //contextMenu: ['remove_row'],
    rowHeaders: true,
    filters: true,
    dropdownMenu: ['filter_by_condition', 'filter_action_bar'],
    height: 400,
    outsideClickDeselects: false,
    hiddenRows: {
      indicators: false
    }
  };
}

 ngOnInit() {
   this.auth.getUser().subscribe(
    usr => {
      console.debug('parts.ngOnInit()');
      console.debug(usr);
      this.fetchData();
    }, e => console.debug(e)
  );
 }

fetchData():void {
  console.debug("fetchData()")
  this.repositoryService.getParts()
    .subscribe(
      parts => this.dataset = parts,
      err => this.error = true,
      () => this.fetched = true
    );
}


onAfterChange($event) {
  console.debug('onAfterChange()'); \\ <--- not being called 
  console.debug($event);

}



}

【问题讨论】:

  • 你有没有想过这个问题?同样的问题。
  • @oakfish56 看看我的回答,希望对你有帮助。

标签: angular handsontable


【解决方案1】:

你没有说你正在使用的angular-handsontable 版本。我的回答是基于当前版本。

Handsontable 钩子不是 Angular 事件。事件是“触发并忘记”类型的函数,Handsontable 使用回调,因此它们可以取消操作或修改数据。回调应该绑定为输入,而不是输出。

查看angular-handsontable 发行说明了解详细信息:https://github.com/handsontable/angular-handsontable/releases/tag/2.0.0

【讨论】:

    猜你喜欢
    • 2015-09-17
    • 2018-08-07
    • 2018-06-11
    • 1970-01-01
    • 2010-11-08
    • 2019-01-31
    • 2013-04-09
    • 2015-07-25
    • 2017-06-25
    相关资源
    最近更新 更多