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

How can I customize the visibility toggles for the password input field in Angular Material?

Currently immersed in the Angular 15 migration process... Today, I encountered an issue with a password input that displays two eyes the first time something is entered in the field. The HTML code for this is as follows: <mat-form-field appearance=&qu ...

The issue of "Invalid arguments passed to jsPDF.text" encountered while using jsPDF on an nginx server

In my project admin, I have successfully implemented jspdf. The admin panel works perfectly fine on localserver. However, when I deploy it to a live nginx server, the server side throws an error: Error: Uncaught (in promise): Error: Invalid arguments passe ...

Angular2 ngIf can cause disruption in the styles of elements

In my Angular 2 app, I have integrated an MDL stepper element. It is placed inside a div container. However, when I add the *ngIf directive with a condition to this div, the stepper component breaks completely. Surprisingly, without the *ngIf directive, th ...

Can Observable subscriptions in Angular be tested?

I'm a newcomer to angular and I'm currently working on creating unit tests for the function below. HomeComponent.ts ngOnInit() { this.msalBroadcastService.inProgress$ .pipe( filter((status: InteractionStatus) => status === ...

Angular 2 GET request returns a 404 error

I have been attempting to reproduce the ngPrime datatable demo from this Github repository. Currently, I am working with the most recent version of Angular (4) and using angular-cli in development mode. Placing a JSON file into my app folder where the serv ...

Animating with Angular 2

As I delve into this informative resource, my goal is to incorporate some animations into my applications, but I find myself grappling with understanding how the animations are triggered. HTML Component <div class="navbar navbar-default navbar-fixed-t ...

Struggling to use the bind method for the loadScene callback function in cocosCreator or cocos2d-x?

When the loadScene() callback function is bound, the information retrieved from getScene() becomes inaccurate. Upon transitioning from the Entry Scene to the Lobby Scene, I perform post-processing tasks. The implementation was done in TypeScript. Entry. ...

Definition of a Typescript Global.d.ts module for a function that is nested within another function

Simply put, I have a npm module that exports a function along with another function attached to it: // @mycompany/module ... const someTool = (options) => { // do some cool stuff }; someTool.canUseFeature1 = () => { return canUseSomeFeature1(); ...

Incorporate the Angular router within markdown hyperlinks

When utilizing ngx-markdown to display my FAQ, I include links to both external resources (beginning with http) and internal content (starting with /). I am interested in passing the Angular router to my markedOptionsFactory so that I can easily navigate ...

Error: The recursive list cannot access the 'length' property of an undefined value

I am experiencing an issue with my recursive list, as I am unable to retrieve the entire list. <ul> <ng-container *ngTemplateOutlet="recursiveListTmpl; context:{ list: famillies }" ></ng-container> </ul> <ng-te ...

Exploring ways to send data to WebView in Flutter

How can I pass the location obtained in my Flutter app to a WebView for further processing within the opened site? var userLocation = Provider.of<UserLocation>(context); Here is my WebView setup: WebView( initialUrl: widget.url, javasc ...

Trouble accessing images from database in Angular 2 with Firebase

Recently, I've integrated an image upload feature for my database using the following function: private saveFileData(upload: Upload): void { this.firebaseAuth.authState.subscribe(auth => { this.db.list(`uploads/${auth && auth.email && au ...

Error 403 persists despite my login status!

Currently, I am in the process of developing a project using Django and Angular. In this project, I decided to utilize the base user model for Django users and implemented JWT authentication on both the Django and Angular sides. After setting up the neces ...

Issue with navigating history back in Angular 7 using an iframe

I'm currently working on a single-page application using Angular. I encountered an issue where, when the user presses the browser's back button, only the YouTube iframe content updates and not the entire page. This results in having to press the ...

Transfer websites to subfolders without altering the base URL

Previously, I had two staging/test servers each hosting an angular application on nginx, referred to as app1 and app2. The setup was straightforward: http://<ip for app1 server>/ => app1 http://<ip for app2 server>/ => app2 Now, my g ...

Is there a way to develop a unique Angular directive that can toggle the visibility of a child element when a neighboring element is clicked?

Is there a way to create a unique Angular directive that can reveal and conceal a child element when a neighboring element is clicked? I would like the ability to display "custom_elem" using custom directives when the h2 element is clicked. It's imp ...

Unable to render ASP.NET Core 2 WebAPI and Angular application on the webpage

Following a tutorial, I created an ASP.NET Core 2 Web API. The API functions properly when accessed through the browser at: https://localhost;44313/api/liveconsole To design the Angular UI for my web API, I referred to another tutorial. After multiple at ...

Accept an empty string as the defaultValue, but disallow it during validation using Zod, react-hook-form, and Material UI

Currently, I am working with material ui components alongside react-hook-form and zod validation in my project. One of the challenges I encountered is with a select field for a bloodType: const bloodTypes = [ "A+", "A-", "B+", ...

Creating a global variable in Angular 4 and Ionic 3 is simple when following these steps

Currently, I am developing an application in ionic3 and within it, there are numerous services and functions that utilize specific variables such as: let apiUrlPublic = 'http://localhost:8080/'; let apiUrl = 'http://localhost:9999/api/&apo ...

What is the Angular alternative to control.disable when working with a QueryList?

I have encountered a challenge in my Angular form where I need to disable certain fields. The issue arises from the fact that many of the HTML tags used are customized, making it difficult to simply use the disabled attribute. To address this, I have opted ...