简体   繁体   English

列上下文菜单复选框在ag-grid中切换

[英]column context menu checkbox toggle in ag-grid

I am trying to add the context menu checkbox for whole column in ag-grid. 我正在尝试为ag-grid中的整个列添加上下文菜单复选框。 By following this tutorial I was able to add a checkbox to my custom menu by setting checked : true but this is not a togglable checkbox. 通过遵循教程,我可以通过将checked : true设置为checked : true来向我的自定义菜单添加一个复选框,但这不是可切换的复选框。 it is always set to true only. 它始终仅设置为true。 How to make it togglable? 如何使其可翻转?

First you have to define the context of the grid options as follows: context: { thisComponent: this } 首先,您必须定义网格选项的上下文,如下所示: context:{thisComponent:this}

public gridOptions: any = {
   columnDefs: this.columnDefs,
   rowData: this.rowData,
   enableSorting: false,
   enableFilter: false,
   context: { thisComponent: this }
}

Then you have to create your own function which returns true or false: 然后,您必须创建自己的函数,该函数返回true或false:

public checkedContextMenuFunction(params): boolean {
   if (){
       return true;
   }else {
       return false;
   }
}

and add it to the contextMenuItems function: 并将其添加到contextMenuItems函数:

checked: params.context.thisComponent.checkedContextMenuFunction(params) 检查: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);
       }
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM