代码之家  ›  专栏  ›  技术社区  ›  Anshuman Jaiswal

ng2智能表格:从自定义renderComponent计算其他列值

  •  0
  • Anshuman Jaiswal  · 技术社区  · 8 年前

    我创造了一个 stackblitz 代码。

    我想更新 Total 有关更改 Quantity .在自定义组件中更新时 total 在数据中,当数据被更新时,它不会在UI中被更新(我可以在控制台中看到)。

    这是一个具体的问题 ng2-smart-table .

    1 回复  |  直到 8 年前
        1
  •  2
  •   Sunil Singh    8 年前

    你应该使用 LocalDataSource 以便您可以告诉ng2表某些内容已更改,它应该刷新数据 source.refresh()

    应用程序中的更改。组成部分ts

    source: LocalDataSource;
    

    改变环境

     quantity: {
            title: 'Quantity',
            type: 'custom',
            renderComponent: CustomComponent,
            sort: false,
            editable: true,
            onComponentInitFunction: (instance: any) => {
              instance.save.subscribe(row => {
                this.source.refresh();
              });
            }
          },
    

    习俗的改变。成分。ts

    export class CustomComponent {
    
        rowData: any;
    
       @Output() save: EventEmitter<any> = new EventEmitter();
    
        onModelChange(table) {
            this.rowData.total = this.rowData.amount * this.rowData.price;
            this.save.emit(this.rowData);
        }
    }
    

    工作演示在这里- https://stackblitz.com/edit/ng2-smart-table-column-cal-m9nxpg

    推荐文章