我是Angular的新手,在找到解决方法之前,我遇到了一些严重的问题。使用此链接预览解决方案
<https://plnkr.co/edit/OtJI13uA89caf8TG5lbI?p=preview>?
发布于 2017-10-18 23:22:48
要动态填充NG2智能表,您可以按照以下步骤操作。1.在模块中导入智能表组件。从“NG2-smart-table”导入{ LocalDataSource };
2.将以下代码添加到类中。
@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++;
}
}
https://stackoverflow.com/questions/46813753
复制相似问题