【问题标题】:Programmatically set p-tableCheckbox以编程方式设置 p-tableCheckbox
【发布时间】:2018-08-01 05:17:45
【问题描述】:

我有一个嵌套的 turbotable(p-table 内的 p-table),带有复选框和可扩展的行。

我希望能够以编程方式设置某些复选框,例如如果用户在嵌套表中选择了一行,那么父行的复选框也应该被选中。

查看StackBlitz

【问题讨论】:

    标签: angular primeng primeng-turbotable


    【解决方案1】:

    我对您加入的代码进行了很多更改,但主要部分是 cmets :

    updateParentSelection(i, parentRow) {
        if (this.cars[i].length > 0) { // if subselection not empty
          if (this.parentSelection.indexOf(parentRow) === -1) { // if parent row not already selected
            this.parentSelection = this.parentSelection.concat(parentRow); // add parent row to parent selection
          }
        } else { // if subselection empty
          this.parentSelection.splice(this.parentSelection.indexOf(parentRow), 1).slice(0); // remove parent row from parent selection
          this.parentSelection = [].concat(this.parentSelection.splice(this.parentSelection.indexOf(parentRow), 1).slice(0)); // trick to update the view
        }
      }
    

    如果您有任何问题,请不要犹豫。

    见分叉StackBlitz

    【讨论】:

    • 这很好用。一个问题:谁在调用这个函数updateParentSelection
    • 没关系。我看到了。它在点击子复选框时被调用。非常感谢!
    猜你喜欢
    • 2020-09-08
    • 2021-11-21
    • 2018-11-26
    • 2011-04-18
    • 2012-07-18
    • 2016-02-15
    • 2014-07-26
    • 1970-01-01
    • 2011-06-06
    相关资源
    最近更新 更多