以编程方式设置 p-tableCheckbox
Programmatically set p-tableCheckbox
我有一个嵌套的 turbotable(p-table inside p-table),带有复选框和可扩展行。
我希望能够以编程方式设置某些复选框,例如如果用户在嵌套的 table 中选择一行,那么父行的复选框也应该被选中。
勾选这个StackBlitz
我对您加入的代码做了很多更改,但主要部分在此处并带有注释:
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
我有一个嵌套的 turbotable(p-table inside p-table),带有复选框和可扩展行。
我希望能够以编程方式设置某些复选框,例如如果用户在嵌套的 table 中选择一行,那么父行的复选框也应该被选中。
勾选这个StackBlitz
我对您加入的代码做了很多更改,但主要部分在此处并带有注释:
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