Having trouble with my ag-grid context menu not functioning properly

I am aiming to display a context menu when the user right-clicks on a cell.

Unfortunately, my code is not responding to the right click event. I have been unable to locate where I may have made a mistake.

Here is the snippet of my code that seems to be causing the issue. I inserted the log statement "console.log("getContentMenuItems()");" but it does not appear in the console output.

my-grid-application.component.ts

export class MyGridApplicationComponent implements OnInit, OnDestroy {
  gridOptions: GridOptions;
  private subscription: Subscription;
  private isPubPark: boolean = false; 
  private getContextMenuItems;

  constructor(private commCodeGridOptionService: CommCodeGridOptionService, private commonService: CommonService) { 
    console.log("MyGridApplicationComponent: Constructor()");

    let params = new URLSearchParams(window.location.search.substring(1)); 
    this.isPubPark = (params.get('isPubPark') == 'true');
    console.log("params:" + params + ", " + params.get('isPubPark') + ", isPubPark: " + this.isPubPark);

    this.commCodeGridOptionService.setTarget(this.isPubPark);
    this.commCodeGridOptionService.fetchColumnDefs();
    this.commCodeGridOptionService.getColumnDefMessage().subscribe(message => {
      console.log("MyGridApplicationComponent:getColumnDefMessage()");
      this.gridOptions.columnDefs = this.commCodeGridOptionService.gridOptions.columnDefs;
      this.gridOptions.api.setColumnDefs(this.gridOptions.columnDefs);      
    });

    this.commCodeGridOptionService.getRowDataMessage().subscribe(message => { 
      console.log("MyGridApplicationComponent getRowDataMessage().subscribe()");

      this.gridOptions.rowData = this.commCodeGridOptionService.commcodeSitesList;

      //The gridOptions api will be set and ready to use once the grid's gridReady event has been called.
      this.gridOptions.api.setRowData(this.gridOptions.rowData);
    });

    this.getContextMenuItems = function getContextMenuItems(params) {
      console.log("getContentMenuItems()");
      var result = [
        {
          name: "Always Disabled",
          disabled: true,
          tooltip: "Very long tooltip, did I mention that I am very long, well I am! Long!  Very Long!"
        },
        "separator",
        "copy"
      ];
      return result;
    };
  }

  ngOnInit() {
    console.log("MyGridApplicationComponent: ngOnInit()");
    this.gridOptions = {};

    this.subscription = this.commonService.notifyObservable$.subscribe((res) => {
      console.log(res);
      if (res.hasOwnProperty('option') && res.option === 'onCommCodeSelected') {
        this.changeCommCodeFilter(res.value);
      }
    });
  }

  //set filter to commcode when click commCodeDesc component
  public changeCommCodeFilter(commcode: string) {
    console.log("changeCommCodeFilter() ", commcode);

    let ageFilterComponent = this.gridOptions.api.getFilterInstance('commCode');
    ageFilterComponent.setModel({
        type: 'equals',
        filter: commcode,
        filterTo: null
    });
    this.gridOptions.api.onFilterChanged();
    window.scrollTo(0,0);
  }

  ngOnDestroy() {
    this.subscription.unsubscribe();
  }
}

my-grid-application.component.html

<h3><a href='/?isPubPark={{!isPubPark}}'></a></h3>
<app-comm-code-selectbox></app-comm-code-selectbox>
<div style="width: 100%; height:700px">
  <ag-grid-angular #agGrid 
      style="width:100%;height:100%;" 
      class="ag-fresh" 
      [gridOptions]="gridOptions"
      [enableRangeSelection]="true"
      [allowContextMenuWithControlKey]="true"
      [getContextMenuItems]="getContextMenuItems"
      rowHeight=100
      enableSort 
      enableFilter
      enableColResize>
  </ag-grid-angular>
</div>  

Answer №1

Remember, the context menu feature in your enterprise application requires a separate installation:

npm install ag-grid-enterprise

After importing ag-Grid for Angular, you need to include it in your module like this:

import { AgGridModule } from 'ag-grid-angular'; 
import'ag-grid-enterprise'; 

Once you follow these steps, everything should work smoothly!

Answer №2

To access the menu module for ag-grid enterprise, you need to follow these steps:

npm install @ag-grid-enterprise/menu

Once installed, import the MenuModule into your component:

import { MenuModule } from '@ag-grid-enterprise/menu';

Next, configure your grid to utilize this module:

In your .ts file:

gridModules = [MenuModule, ...];

In your template:

<ag-grid-angular [modules]="gridModules" ...

If needed, remember to set suppressContextMenu = false; and implement the getContextMenuItems function.

Answer №3

To set up React with ag-Grid:

  1. Ensure that the menu package from ag-grid enterprise is installed.
npm install @ag-grid-enterprise/menu
  1. Implement the getContextMenuItems method as detailed in the ag-Grid documentation.
  2. Include the following attributes in your ag-Grid instance.
suppressContextMenu={false}
allowContextMenuWithControlKey={true}
getContextMenuItems={getContextMenuItems}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using React Native with TypeScript to Select the Parent and Child Checkboxes within a FlatList

My objective is to ensure that when a user selects a checkbox for one of the parent items ('Non Veg Biryanis', 'Pizzas', 'Drinks', 'Desserts') in the flatlist, all corresponding child items should also be selected au ...

The HTML code is not displaying the value from the array

How can I use interpolation to display a response from an API? I have attempted the following: response['data'][0].value// can console this value here this.variable = response; <p>{{ variable['data'][0].value }}</p> T ...

When attempting to use a value outside of its block, the function may return a

My current task involves querying one collection to retrieve IDs, then using those IDs to query another collection and send back the response. The process runs smoothly until I encounter an issue with retrieving values outside of a block when using forEach ...

Obtain the promise value before returning the observable

I'm facing an issue with the code below, as it's not working properly. I want to return an observable once the promise is resolved. Any thoughts or suggestions would be greatly appreciated. getParalelos() { let _observable; this.getTo ...

Adding a new value to a string variable using TypeScript

Just starting out with Angular and I'm looking to capture user input from a text box with each keystroke and add it to a string variable like in Java. In my text box, I have the following setup for capturing key events: <input type="text" ...

After installing a new npm package, certain components within my project suddenly stopped functioning properly, specifically those using

I recently attempted to integrate the ngx-markdown-editor from this source into my project. However, upon installing the npm package for this editor, I encountered an issue where one of my other components located in a completely different part of the proj ...

Creating Meta tags for Dynamic Routes in a Nuxt 3 Build

I recently encountered an issue when trying to implement dynamic OpenGraph meta tags on a dynamically generated route in Nuxt 3 (and Vue 3). I attempted to set the meta tags dynamically using Javascript, as it was the only dynamic option supported by Nuxt ...

In Visual Studio Code, beautification feature splits HTML attributes onto separate lines, improving readability and code organization. Unfortunately, the print width setting does not apply

I have done extensive research and tried numerous solutions, When using Angular and formatting HTML with Prettier, it appears quite messy as it wraps each attribute to a new line, for example: <button pButton class="btn" ...

Ag-Grid is displaying a third column that is not present in my dataset

Recently, I've been working with Angular and incorporating the Ag-Grid into my project. My goal is to display a grid with two columns; however, upon implementation, an unexpected third separator appears as if there are three columns in total. Even w ...

Convert HTML Form to PDF or Docx with Angular 4

My current setup involves Angular 4 with Node and MySQL. I have a form that, upon submission, needs to trigger a Save As... dialog box for the user to save the entered form contents as either a PDF or Word Doc. I've attempted using htmlDox and saveAs ...

The PassportJS logged in feature always yields a result of zero

After successfully implementing passportJS in my application, I encountered an issue with the current connected user. When using (req.isAuthenticated()), it always returns "0". Here is the code snippet from auth.js: /* Passport - Sessions - Cookies D ...

NG2-smart-table Icons not appearing when using ngx-admin theme

In implementing my ng2-smart-table within an Angular project, I have utilized the ngx-admin theme for styling. Following the documented configuration steps involved installing necessary dependencies and importing required styles in my styles.scss file. Th ...

Incorporating the id attribute into the FormControl element or its parent in Angular 7

I'm attempting to assign an id attribute to the first invalid form control upon form submission using Angular reactive forms. Here is my current component code: onSubmit() { if (this.form.invalid) { this.scrollToError(); } else { ...

React Project Encounters NPM Installation Failure

I recently started delving into the world of React and experimenting with different examples. Everything was running smoothly until I attempted to start the server [npm start] and encountered an error as shown below. Despite my best efforts, I can't p ...

What is the best approach for declaring helper functions and constants within nest.js?

Currently, I am delving into the world of nest.js and building an API using it. However, I have hit a roadblock when it comes to defining constants and helper functions. Like many APIs, some of my endpoints require pagination, and I want to set a default ...

Steps for developing a versatile function Component

Can I create generic function components? I thought that the following example would work: type MyComponentProps<T> = T & { component: ComponentType<T>, primary?: boolean, size?: 'S' | 'M' | 'L' ...

How can I access the value of one method within the same class and use it in another method in Ionic?

I encountered an error while trying to utilize data from my API call in IONIC's home.ts file for the google map method also located in home.ts. Unfortunately, this resulted in a null or undefined error. Is there a way to effectively use data from one ...

Tips for setting up a React TypeScript project with custom folder paths, such as being able to access components with `@components/` included

I'm looking to streamline the relative url imports for my React TypeScript project. Instead of using something messy like ../../../contexts/AuthContext, I want to simplify it to just @contexts/AuthContexts. I attempted to update my tsconfig.json with ...

TypeScript(error:2532): object may be undefined despite null or undefined check

Currently, I am developing a Discord-bot using TypeScript which includes a command to retrieve information from an airport. To do this, users only need to provide the 4-character ICAO code that identifies the specific airport. However, due to potential use ...

Ways to mimic an object and confirm that a specific parameter was passed to the mimic

I am currently experimenting with testing an HttpInterceptor, using ng-mocks: @Injectable() export class AuthTokenInterceptor implements HttpInterceptor { constructor(private store: Store) {} intercept(req: HttpRequest<any>, ...