简体   繁体   中英

column context menu checkbox toggle in ag-grid

I am trying to add the context menu checkbox for whole column in 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. it is always set to true only. How to make it togglable?

First you have to define the context of the grid options as follows: 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:

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

and add it to the contextMenuItems function:

checked: 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);
       }
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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