[英](Ag-Grid) While editing, how to get value changed immediately, not after cell loses focus?
在 ag-grid 中,在表中输入一些值时,我需要接收input
或change
事件的更新值。
但是onCellValueChanged
仅在单元格失去焦点时触发,我无法弄清楚立即获取值的方法是什么。 我唯一的限制 - 我不能添加自定义 cellEditor,它需要是网格默认值。
有人可以建议如何达到这种行为吗?
根据ag-grid,您可以使用自定义回调onCellEditingStopped
。
这将在每次单元格编辑结束时触发。
您可以直接在网格选项对象上定义它,您还可以像这样访问编辑过的值(及其行和列):
const gridOptions = {
columnDefs: [/* whatever */],
defaultColDef: {/* whatever */},
rowData: rowData,
onCellEditingStopped: function(event) {
console.log(event);
console.log(event.oldValue); // cell's previous value
console.log(event.newValue); // cell's new value
console.log(event.column); // the column that was edited
console.log(event.data); // the row that was edited
},
};
// setup the grid after the page has finished loading
document.addEventListener('DOMContentLoaded', function() {
var gridDiv = document.querySelector('#myGrid');
new agGrid.Grid(gridDiv, gridOptions);
});
这里有关于何时触发onCellEditingStopped
的详细说明。
您还可以检查完整示例。
您可以在编辑时通过利用 Grid Event onCellKeyDown
获取单元格的当前值:
https://www.ag-grid.com/javascript-grid/keyboard-navigation/#keyboard-events
var gridOptions = {
onCellKeyDown: params => {
console.log('current value', params.event.target.value)
},
}
请查看展示此示例的示例: https : //plnkr.co/edit/GbMglD1fxTTeSZFj
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.