首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在angular 4中动态填充ng2-smart-table的列

如何在angular 4中动态填充ng2-smart-table的列
EN

Stack Overflow用户
提问于 2017-10-18 23:22:48
回答 1查看 3.9K关注 0票数 0

我是Angular的新手,在找到解决方法之前,我遇到了一些严重的问题。使用此链接预览解决方案

代码语言:javascript
复制
 <https://plnkr.co/edit/OtJI13uA89caf8TG5lbI?p=preview>?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-18 23:22:48

要动态填充NG2智能表,您可以按照以下步骤操作。1.在模块中导入智能表组件。从“NG2-smart-table”导入{ LocalDataSource };

2.将以下代码添加到类中。

代码语言:javascript
复制
     @Component({
      selector: 'my-app',
      template: `
        <div>
          <h2>Hello {{name}}</h2>
          <button (click)="addColumn()">Add Column</button>
          <ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>
        </div>

      `,
    })
     export class ResultComponent implements OnInit
      {
      source: LocalDataSource;
      i = 0;
      settings;
      mySettings = {
      mode: 'inline',
      actions: {
           delete:false,
        },
      add: {
      confirmCreate: true,
      },
      delete: {
      confirmDelete: true,
      },
      edit: {
      confirmSave: true,
      },
      columns: {

      }
      };

   //method that adds the column. You can use trigger events to do this
    public addColumn() {
          this.mySettings.columns["new column " + this.i] = { title: 'new column 
         ' + this.i.toString()};
          this.settings = Object.assign({}, this.mySettings);
          this.i++;
      }

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

https://stackoverflow.com/questions/46813753

复制
相关文章

相似问题

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