简体   繁体   English

Ag-grid 从外部触发事件

[英]Ag-grid trigger events from outside

I am working with ag-grid.我正在使用 ag-grid。 I have event handlers defined in my gridOptions :我在gridOptions定义了事件处理程序:

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

When cell editing starts/stops - everything works great.当单元格编辑开始/停止时 - 一切正常。 But at some point I need to trigger these events from other .js file, where I don't even have ag-grid instance.但在某些时候,我需要从其他 .js 文件触发这些事件,我什至没有 ag-grid 实例。

I'm trying something like this:我正在尝试这样的事情:

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

But unfortunately it doesn't work.但不幸的是它不起作用。 What am I doing wrong?我究竟做错了什么? Is it possible to trigger events for ag-grid in this way or I need some more code to write?是否可以通过这种方式触发 ag-grid 的事件,或者我需要编写更多代码?

This is solution i've found to achieve 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();
                });
            },
...
}

So in my other file i can do something like this:所以在我的另一个文件中,我可以做这样的事情:

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

This solution looks clean for me and i don't have to move my grid instance to another file somehow.这个解决方案对我来说看起来很干净,我不必以某种方式将我的网格实例移动到另一个文件。 Hope it will help others somehow希望它能以某种方式帮助别人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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