【问题标题】:How can I implement table footer of ng2-smart-table?如何实现 ng2-smart-table 的表页脚?
【发布时间】:2017-06-21 21:55:29
【问题描述】:

我现在正在我的应用程序中实现 ng2-smart-table。我想在表格下方显示表格页脚以获取附加信息,例如总金额、折扣金额等。

这是我在打字稿文件中的代码

settings = {
    columns: {
      seq: {
        title: '#',
        editable: false,
        width: '10%'
      },
      productName: {
        title: 'Product Name',
        editable: false
      },
      qty: {
        title: 'Qty.',
        width: '10%'
      },
      uom: {
        title: 'Uom',
        width: '10%'
      },
      price: {
        title: 'Price',
        valuePrepareFunction: (price) => {
          var formatted = this.thbCurrencyPipe.transform(price, 2);
          return formatted;
        }
      },
      discount: {
        title: 'Disc.'
      },
      amount: {
        title: 'Amount'
      }
    }
  };

我在ngOnInit()方法中加载数据

ngOnInit() {
    this._utilityService.LoadPosDummyData().subscribe(data => {
      console.log(data);
      this.datas = data;
    });
  }

这是我在 Html 中使用的ng2-smart-table 标签

<ng2-smart-table [settings]="settings" [source]="datas"></ng2-smart-table>

【问题讨论】:

  • 为它创建一个单独的组件
  • 这取决于您存储数据的方式,但reduce 函数可能符合您的要求。如果您提供一些代码,我可以更好地帮助/解释。
  • @MichaelSolati 我已经在上面添加了代码 sn-p,谢谢 :)

标签: angular ng2-smart-table


【解决方案1】:

我会创建一个单独的组件来显示您想要的 Sum 信息,监听主表上的数据更新并更新页脚组件。

在你的 html 上

<ng2-smart-table #grid

在你的组件上

@ViewChild('grid')
table;

订阅来自智能表的 on changed source observable

ngAfterViewInit(): void {
    this.table.grid.source.onChangedSource.subscribe(() => {
        // update other component with the SUM
    });
}

【讨论】:

  • 感谢@hamilton.lima 的回答,现在我创建了另一个部分作为页脚来总结信息。
  • 我已经像上面那样尝试过,但它对我不起作用。在未定义的 this.table.grid.source 网格中显示错误。请你用一些清晰的例子更新你的代码。跨度>
猜你喜欢
  • 2019-08-10
  • 2017-08-15
  • 2020-07-08
  • 1970-01-01
  • 1970-01-01
  • 2017-11-23
  • 1970-01-01
  • 2019-01-08
  • 2020-01-03
相关资源
最近更新 更多