访问单元格渲染器创建的网格的 gridOptions
Get access to gridOptions of grid created by cell renderer
我正在使用 ag-Grid 通过单元格渲染器在网格内创建网格。这是单元格渲染器的代码。
// cell renderer class
function TestCellRenderer() {
}
// init method gets the details of the cell to be rendered
TestCellRenderer.prototype.init = function(params) {
this.eGui = document.createElement('div');
// console.log('params.value:', params.value);
// console.log('eGui', this.eGui.style);
this.eGui.style.width = '70%';
this.eGui.classList.add("ag-theme-balham");
this.gridOptions = {
columnDefs: params.columns,
rowData: rowDataContained,
domLayout: "autoHeight",
rowHeight: 50,
// suppressRowClickSelection: true,
popupParent: document.querySelector('body'),
rowDragManaged: true,
components: {
'actionCellRenderer': ActionCellRenderer,
'selectCellRenderer': SelectCellRenderer
},
onCellEditingStopped: function(event) {
console.log('cellEditingStopped');
},
onRowClicked: function(event) { console.log('A row was clicked:', event); },
}
// console.log('gridOptions:', this.gridOptions);
new agGrid.Grid(this.eGui, this.gridOptions);
};
TestCellRenderer.prototype.getGui = function() {
return this.eGui;
};
这张截图将更好地解释我所做的事情。
我的问题是,我已经为“下拉”列创建了一个 select2 单元格编辑器,但是当用户单击select 菜单,因为它需要使用渲染器即时创建的 gridOptions。
如果用户将焦点切换到不同的单元格,编辑会停止,但我希望能够在用户 select 设置值时停止编辑。当用户 select 有东西时,我能够在控制台上打印一些东西,但我不知道如何访问该特定网格的 gridOptions。
对于任何想知道的人,我通过将以下内容添加到我的 selectCellEditor.prototype.init 函数中解决了这个问题:
$(this.eInput).on('select2:select', function(e) {
console.log('Works!', this);
params.stopEditing();
});
发生的事情是,当用户选择一个选项时,菜单关闭并且单元格中的值发生更改。
我正在使用 ag-Grid 通过单元格渲染器在网格内创建网格。这是单元格渲染器的代码。
// cell renderer class
function TestCellRenderer() {
}
// init method gets the details of the cell to be rendered
TestCellRenderer.prototype.init = function(params) {
this.eGui = document.createElement('div');
// console.log('params.value:', params.value);
// console.log('eGui', this.eGui.style);
this.eGui.style.width = '70%';
this.eGui.classList.add("ag-theme-balham");
this.gridOptions = {
columnDefs: params.columns,
rowData: rowDataContained,
domLayout: "autoHeight",
rowHeight: 50,
// suppressRowClickSelection: true,
popupParent: document.querySelector('body'),
rowDragManaged: true,
components: {
'actionCellRenderer': ActionCellRenderer,
'selectCellRenderer': SelectCellRenderer
},
onCellEditingStopped: function(event) {
console.log('cellEditingStopped');
},
onRowClicked: function(event) { console.log('A row was clicked:', event); },
}
// console.log('gridOptions:', this.gridOptions);
new agGrid.Grid(this.eGui, this.gridOptions);
};
TestCellRenderer.prototype.getGui = function() {
return this.eGui;
};
这张截图将更好地解释我所做的事情。
我的问题是,我已经为“下拉”列创建了一个 select2 单元格编辑器,但是当用户单击select 菜单,因为它需要使用渲染器即时创建的 gridOptions。
如果用户将焦点切换到不同的单元格,编辑会停止,但我希望能够在用户 select 设置值时停止编辑。当用户 select 有东西时,我能够在控制台上打印一些东西,但我不知道如何访问该特定网格的 gridOptions。
对于任何想知道的人,我通过将以下内容添加到我的 selectCellEditor.prototype.init 函数中解决了这个问题:
$(this.eInput).on('select2:select', function(e) {
console.log('Works!', this);
params.stopEditing();
});
发生的事情是,当用户选择一个选项时,菜单关闭并且单元格中的值发生更改。