[英]disable checkbox selection in Ag-grid
是否可以通過保留一些使用某些約束呈現的選定行來禁用復選框選擇? 我不想讓用戶取消選擇在呈現時選擇的行。
我發現this.gridOptions.suppressCellSelection = true;
但這只是隱藏了復選框,而我需要在禁用模式下顯示復選框。
謝謝。
我通過在 GridOptions 中添加rowClassRules
來解決它
rowClassRules: {
'ag-row-selected' : function(params) {
return params.node.selected === true;
},
},
這將添加如下 css 以禁用復選框單擊
.ag-row-selected{
.ag-cell .ag-cell-wrapper .ag-selection-checkbox .ag-icon-checkbox-checked {
pointer-events: none;
}
}
更新/刷新網格或更新節點時應用 RowClass 規則。 我是通過更新特定節點來做到的
node.setSelected(true);
// this is to trigger rowClass for selected/non-selected rows
// to disable checkbox selection
node.setData(node.data);
這對我有用
cellStyle: params => {
return params.data.myStatus ? {'pointer-events': 'none', opacity: '0.4' }
: '';
}
一種方法是向需要實現復選框的列添加一個 cellRenderer 函數。 您可以通過從 cellRenderer 函數返回 true 或 false 來啟用或禁用復選框。
如果您使用內置的agGroupCellRenderer
來渲染多選復選框,您可以在決定是否渲染復選框時關閉節點的selectable
標志。
cellRenderer: "agGroupCellRenderer",
cellRendererParams: {
checkbox: function(params) {
const node = params.node;
const isGroupRow = node.level === 0; //only show the checkbox on group row.
if(isGroupRow) {
params.node.selectable = //your condition whether the rendered checkbox is selectable or not
}
return isGroupRow;
}
}
純 CSS 解決方法:
.ag-selection-checkbox.ag-hidden {
display: inherit !important;
opacity: 0.6;
cursor: not-allowed;
}
這將覆蓋復選框包裝器的 ag-hidden 中的 display:none 配置。
{ headerName: 'IsActive', field: '', editable: false, cellRenderer: params => { return `<input type='checkbox' disabled=true ${params.data.IsActive ? 'checked' : ''} />`; } }
如果您想在找不到過濾數據時禁用 ag-grid 復選框的標題,那么這可能會有所幫助
headerCheckboxSelectionFilteredOnly:true
上面的解決方案有效,但是當用戶單擊標題中的全選或取消全選選項時,這會自動更改
在 28.1.0 版本中,AG 網格添加了顯示禁用復選框的功能。 這里的更新日志https://www.ag-grid.com/changelog/?fixVersion=28.1.0 。 這是官方文檔https://www.ag-grid.com/react-data-grid/row-selection/#example-disabled-checkboxes中的示例 此外,還有一項功能允許選中和禁用復選框。 例如https://www.ag-grid.com/react-data-grid/row-selection/#example-force-enable-checkboxes
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.