首页 > 解决方案 > 如何动态更新 ng2-smart-table 的自定义部分?

问题描述

在我的 Angular 6 应用程序中,我使用了 ng2-smart-table。现在我需要根据访问权限显示和隐藏自定义操作功能。

我能够管理addedirdelete部分。有了这个,我还添加了一些自定义图标来获得额外的功能。

custom: [            
  { name: 'up', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-true-icon">' },
  { name: 'up-cancel', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-cancel-icon">' },
  { name: 'down', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-true-icon">' },
  { name: 'down-cancel', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-cancel-icon">' },
]

现在我需要根据访问来管理这个东西。

那么我该如何启用和禁用此图标。

注意:我可以在每一行上应用 css 然后隐藏图标,但我需要在每一行上做一次。

标签: angular6ng2-smart-table

解决方案


您可以在自定义数组中添加图标时添加图标...

试试这个方法

if(access){     // Set you access condition
     this.settings.custom.push('{ name: 'up', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-true-icon">' }');
     this.settings.custom.push('{ name: 'up-cancel', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-cancel-icon">' },');
}else{
    this.settings.custom.push(' { name: 'down', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-true-icon">' }');
    this.settings.custom.push('{ name: 'down-cancel', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-cancel-icon">' }');
}  

这是添加图标的简单方法...因为custom是数组,所以您可以在其中推送图标...

希望这可以帮助你...... :)


推荐阅读