Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ng2智能表将“添加新”按钮事件绑定到外部按钮_Javascript_Angular_Angular6_Ng2 Smart Table - Fatal编程技术网

Javascript Ng2智能表将“添加新”按钮事件绑定到外部按钮

Javascript Ng2智能表将“添加新”按钮事件绑定到外部按钮,javascript,angular,angular6,ng2-smart-table,Javascript,Angular,Angular6,Ng2 Smart Table,我一直在为表格网格使用ng2智能表格插件。有一个addnew按钮将条目添加到表中 但是我只想从一个外部按钮触发'addnew'事件,该按钮可能位于表的顶部,但不在表内。这与我的要求完全相反。这可以通过使用“模式:外部”来实现 目前,这是一个开放的问题,与他们的 如果他们没有Ng2智能表选项,是否仍有将事件绑定到Angular 6中的其他按钮External?如果是这样,我该怎么做?您可以通过DOM对象事件触发ng2智能表的创建事件 比如说我的ng2智能表的添加按钮设置 add: {

我一直在为表格网格使用ng2智能表格插件。有一个addnew按钮将条目添加到表中

但是我只想从一个外部按钮触发'addnew'事件,该按钮可能位于表的顶部,但不在表内。这与我的要求完全相反。这可以通过使用“模式:外部”来实现

目前,这是一个开放的问题,与他们的


如果他们没有Ng2智能表选项,是否仍有将事件绑定到Angular 6中的其他按钮External?如果是这样,我该怎么做?

您可以通过DOM对象事件触发ng2智能表的创建事件

比如说我的ng2智能表的添加按钮设置

add: {
      addButtonContent : '<span class="add"><i class=""></i></span>',
      createButtonContent:'<i class="far fa-save"></i>',
      cancelButtonContent: '<i class="fas fa-times"></i>',
      confirmCreate: true,
    }

您需要使用LocalDataSource或ServerDataSource

我有同样的问题,在尝试了一些例子之后,我看到了好的一个。 在这部分代码中,他们将loaddata与sourceLocalDataSource一起使用:

constructor(protected service: BasicExampleLoadService) {
   this.source = new LocalDataSource();

   this.service.getData().then((data) => {
     this.source.load(data);
   });
}
然后我尝试使用我的代码,并对LocalDataSource执行了相同的操作,但为了向表中添加一行,我执行了以下操作:

this.source.add({
  name: 'name',
  description: 'desc',
  numQuestions: '8',
});
this.source.refresh();
这对我很管用。 我希望它有帮助。

试试看: 在您的html上:

添加

在您的组件上: @ViewChild“smartTable”smartTable; . . . 添加记录{ this.smartTable.grid.createFormShowed=true; this.smartTable.grid.getNewRow; }

this.source.add({
  name: 'name',
  description: 'desc',
  numQuestions: '8',
});
this.source.refresh();