Initiating ag-grid events from external sources

Currently, I am utilizing ag-grid for my project. Within my gridOptions, there are event handlers defined as follows:

gridOptions = 
{
...
onCellEditingStarted: function (event) { /* magic happens!*/ },
onCellEditingStopped: function (event) { /* magic happens!*/  }
...
}

Everything operates smoothly when cell editing starts or stops. However, I have encountered a situation where I need to trigger these events from another .js file that does not possess an ag-grid instance.

I have attempted the following approach:

$(window).trigger('cellEditingStopped');

Regrettably, this method is unsuccessful. What mistake am I making? Is it feasible to trigger ag-grid events in this manner, or do I require additional code?

Answer №1

I recently discovered a solution that helped me accomplish my goal:

gridOptions = 
{
...
onCellEditingStarted: function (event) { /* magic happens!*/ },
onCellEditingStopped: function (event) { /* magic happens!*/  }
onGridReady: function() {
                $('#gridContainer').off("cell-editing-stop");
                $('#gridContainer').on("cell-editing-stop", function () {
                    gridOptions.api.stopEditing();
                });
            },
...
}

With this approach, I can easily implement the following in another file:

that.OnCellEditingStop = new Event('cell-editing-stop');
$('#gridContainer').trigger('cell-editing-stop');

I find this solution to be efficient and convenient as it allows me to avoid transferring my grid instance to a different file. Hopefully, this method will be beneficial to others as well.

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

The HTML anchor tag paired with the italic tag is a powerful combination for

Here is some example code: <a href="#"> <i class="some-bg" /> Some Text </a> Along with some Javascript: $("a").bind("touchstart", function (e) { e.preventDefault(); console.log("Tag: " + e.target); console.log("Tag Nam ...

What is the clarification regarding accessing JSON from various domains?

(I am aware of the fact that ajax calls must originate from the same domain, and have already gone through relevant responses) However, I am having trouble grasping something: We often see platforms like Facebook use the for(;;) || while(1) pattern in ...

ESLint encountered an error while attempting to load the configuration "next/babel" for extension

Every time I try to generate a build of my Next.js app by running "npm run build," I keep encountering this error. Check out the error I'm getting while running npm run build here. Also, take a look at my .eslintrc.json file here and my .babelrc file ...

The State in the useEffect hook does not update instantly

After conducting some research, I discovered that useState operates asynchronously. However, I am still struggling to resolve my specific issue. My task involves fetching data from an API, but the state is only updated during the second render. Furthermore ...

Loop through the ng-repeat scope object in AngularJS

Is it possible to create rows of 3 using bootstrap and ng-repeat with data from a scope object without the loop repeating every three times due to ng-if? I am curious if something like <h4> {{yogurt[$index+1].name}} </h4> would work. Below is ...

Is there a way to determine if a webpage is being accessed from a website or from a local file system?

While this question has been raised in the past, none of the answers provided seem to be accurate. Unfortunately, I am unable to comment on the original question or answers. Thus, following suggestions given to me, I have decided to create a new question. ...

Linking promises to eliminate nesting

Hi everyone, I am currently working on chaining promises in my code. The initial HTTPS call returns an array of URLs successfully. After that, I loop through them to obtain a JSON object for each one. I am wondering if there is a way to reduce nesting in ...

What is the best method for finding and observing the Javascript code being utilized on a webpage?

Is there a way to find and access specific Javascript used on a webpage? Imagine browsing through a webpage's source code and stumbling upon an element like this: <img border="0" alt="" onmouseout="hidetrail();" onmouseover="showtrail('imag ...

Generating Random Numbers Using Python and JavaScript Pseudo-Random Number Generation Algorithm

I am seeking a means to produce an identical series of pseudo-random integer numbers using both Python and JavaScript. Upon seeding in Python as shown below, I obtain the following outcomes: random.seed(3909461935) random.randint(0, 2147483647) = 1620 ...

Tips for dynamically updating the id value while iterating through a class

Here's the HTML snippet I am working with: <div class="info"> <div class="form-group"> <label class="control-label col-sm-2">Title</label> <div class="col-xs-10 col-sm-8"> <inpu ...

Dealing with CORS, IIS7, and PHP - Overcoming the Access-Control-Allow-Origin obstacle

I am attempting to enable another local host (such as javascript.dev) to make a xhr request to this particular host, which operates on an IIS7 server. When I perform a curl -I command, the headers I receive are as follows: HTTP/1.1 200 OK Content-Length: ...

Guidelines for integrating NPM modules into a vanilla JavaScript and HTML endeavor

I am facing an issue with using axios in my simple project. It doesn't work, but interestingly, when I use CDN for axios, it works perfectly..!! HERE'S MY CODE <!DOCTYPE html> <html lang="en"> <head> <meta char ...

Unable to use .ajax within autocomplete function

I've been struggling for days to make the jQuery autocomplete feature work. Currently, I am able to type in the textbox and see exactly what I want, but the issue arises when I click on the desired option - it does not show up in the textbox. I suspec ...

Using Selenium: Checking for existing dropdown values and incrementing if necessary

I am currently working on automating an application using Selenium Webdriver with Java. The web application I am testing has an Add button that, when clicked, triggers the activation of a dropdown menu. Subsequent clicks on the Add button reveal additional ...

Lustrous Layout

I am developing a mobile app using titanium where I have a scroll view containing objects that occupy 25% of the screen width. I am attempting to create a 'table' layout with these objects, having 4 columns and multiple rows. Is there a way for t ...

What is the process for NPM to execute a command that is not located in the path directory?

When I try to run the ava command from my project directory that contains AVA tests, I encounter an issue because it is not in my path. In my project, the npm test command is configured as ava tests/*.js --verbose, and mysteriously manages to execute the ...

Removing files from the S3 bucket and database simultaneously. Execute each function sequentially

Struggling with an API call that should delete an image from both an S3 bucket and a MySQL database. However, encountering an issue where the S3 image cannot be found because it is being deleted from the database first. // Router code: //req.body is an ar ...

What is the process for completing a form and then going back to edit the data in PHP?

I am having trouble filling out a form and then being able to make changes to the entries later. However, every time I go back to modify the records, I want the form to still have the previous values intact. Unfortunately, when I tried putting " /> An ...

The Parse.com cloudcode refuses to enter the success or error state

Running this code in my Parse cloud, I noticed that when I call it from my app, it never enters the success or error statement. Could it be because the .save method isn't working? Any assistance would be greatly appreciated :) This is how I invoke t ...

Request Timeout: The server took too long to respond and the request timed out. Please try again later

I'm encountering an issue when attempting to send a dictionary as a JSON to the express API. The error message I keep receiving is: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={_NSURLErrorFailingURLSessionTaskErrorKe ...