如何使用 ag-grid 禁用行? [英] how to make row disabled with ag-grid?
问题描述
我与 ag-grid 合作,我发现了如何在文档中禁用列(https://www.ag-grid.com/documentation-main/documentation.php)但在阅读文档后,我从来没有发现如何让 juste 一行被禁用.
I work with ag-grid and i found how to make a column disabled in the doc (https://www.ag-grid.com/documentation-main/documentation.php) but after reading doc i never find how can i make juste one row disabled.
我已经尝试过 editable: params =>params.data.active === true.
也许我没有读对,或者那不存在.有没有人有一些索卢斯的踪迹?
i have already try editable: params => params.data.active === true.
Maybe i didn't read right or that doesn't exist. Is someone here with some soluce track ?
推荐答案
TL;DR
库中没有选项可以禁用单行(基于视觉和键盘事件),我们可以禁用单行的唯一方法是对标题和后续单元格复选框使用 customCellRenderer,这允许完全控制复选框.除此之外,还有其他三种方法可以根据值禁用 ag-grid 复选框,
There is no option in the library to make a single row disabled(both visually and keyboard event based), the only way we could make a single row disabled is by using a customCellRenderer for both header and subsequent cell checkboxes, this allows full control over the checkbox. Besides this, there are three other ways where you can disable ag-grid checkbox based on value,
1)这是使用 checkBoxSelection 参数,它会根据条件清空单元格.
1)This is using checkBoxSelection param, it would empty the cell based on the condition.
checkboxSelection = function(params) {
if (params.data.yourProperty) {
return true;
}
return false;
}
- 这只会禁用点击事件并相应地设置样式,
cellStyle: params => return params.data.status? {'pointer-events': 'none', opacity: '0.4' } : '';
3) 这将完全禁用它,因为您可以控制输入,但您可能必须使用字符串文字,
3)This would disable it completely, as you have control over the input, but you may have to use string literals,
cellRenderer: (params) => {
if (params.value) {
return `<input type="checkbox" checked/>`;
}
else {
return `<input type="checkbox" />`;
}
}
你可以使用 customCellRenderer(customCellRendererParams for props)
, headerCellRenderer(headerCellRendererParams for props) 接受一个完整的 JSX 组件.
You could use customCellRenderer(customCellRendererParams for props)
, headerCellRenderer(headerCellRendererParams for props) which accepts a complete JSX component.
- 我认为这将是最有帮助的,它允许您根据该列的行值选择 cellRenderer 组件.它在 ag-grid 中有很好的描述文档.
这篇关于如何使用 ag-grid 禁用行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!