我正在尝试为 ag-grid 中的整个列添加上下文菜单复选框。
通过关注this教程 我可以通过设置 checked : true
在我的自定义菜单中添加一个复选框,但这不是一个可切换的复选框。它始终仅设置为 true。如何使其可切换?
最佳答案
首先,您必须定义网格选项的上下文,如下所示:context: { thisComponent: this }
public gridOptions: any = {
columnDefs: this.columnDefs,
rowData: this.rowData,
enableSorting: false,
enableFilter: false,
context: { thisComponent: this }
}
然后你必须创建自己的返回 true 或 false 的函数:
public checkedContextMenuFunction(params): boolean {
if (){
return true;
}else {
return false;
}
}
并将其添加到 contextMenuItems 函数中:
已检查:params.context.thisComponent.checkedContextMenuFunction(params)
public getContextMenuItems(params) {
return{
'separator',
{
name: 'Checked menu',
tooltip: 'Tooltip text',
checked: params.context.thisComponent.checkedContextMenuFunction(params),
action: function() {
params.context.thisComponent.differentFunction(params);
}
}
}
关于javascript - ag-grid 中的列上下文菜单复选框切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49750811/