Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ag网格中的列关联菜单复选框切换_Javascript_Datagrid_Ag Grid - Fatal编程技术网

Javascript ag网格中的列关联菜单复选框切换

Javascript ag网格中的列关联菜单复选框切换,javascript,datagrid,ag-grid,Javascript,Datagrid,Ag Grid,我正在尝试为ag网格中的整列添加上下文菜单复选框。 通过遵循教程,我可以通过设置checked:true将复选框添加到自定义菜单中,但这不是一个可切换的复选框。它始终仅设置为true。如何使其可切换?首先您必须定义网格选项的上下文,如下所示:上下文:{thisComponent:this} public gridOptions: any = { columnDefs: this.columnDefs, rowData: this.rowData, enableSorting:

我正在尝试为ag网格中的整列添加上下文菜单复选框。
通过遵循教程,我可以通过设置
checked:true
将复选框添加到自定义菜单中,但这不是一个可切换的复选框。它始终仅设置为true。如何使其可切换?

首先您必须定义网格选项的上下文,如下所示:上下文:{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);
       }
   }
}

首先,必须按如下方式定义网格选项的上下文: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);
       }
   }
}