【发布时间】:2019-04-16 01:32:58
【问题描述】:
我想根据列包含 onCellClicked 事件的特定条件禁用整个列,但我不希望它触发
【问题讨论】:
-
为了将来参考,这里是disabling checkbox in ag-grid的完整信息。
我想根据列包含 onCellClicked 事件的特定条件禁用整个列,但我不希望它触发
【问题讨论】:
使用gridOptions.isRowSelectable,我们可以将特定行设置为可选择或不可选择。下面是来自 ag-grid 文档本身的示例。
gridOptions.isRowSelectable: function(rowNode) {
return rowNode.data ? rowNode.data.year < 2007 : false;
}
【讨论】:
column,而不是row。
您必须在colDef 中定义editable 属性
editable: false <-- edit would be disabled for needed column
更新
标题复选框可用于行选择,对于其他事情,您应该自己创建自定义处理程序。
对于显示处理,您需要创建cellRenderer
对于编辑处理,您需要创建自己的cellEditor
这是您案例的工作示例DEMO
cellRenderer - 复选框将显示为图标
import {Component} from "@angular/core";
import {ICellRendererAngularComp} from "ag-grid-angular";
@Component({
selector: '',
template: `
<div class="checkbox-container">
<span *ngIf="params.value == true" title='true' class='ag-icon ag-icon-tick content-icon'></span>
<span *ngIf="params.value == false" title='false' class='ag-icon ag-icon-cross content-icon'></span>
<span *ngIf="!params.value"></span>
</div>
`
})
export class CheckboxRendererComponent implements ICellRendererAngularComp {
private params: any;
agInit(params: any): void {
this.params = params;
}
refresh(params):boolean{
return true;
}
}
cellEditor - 双击单元格将提供编辑模式(如果可能,基于colDef- editable 属性)
import {Component} from "@angular/core";
import {ICellEditorAngularComp} from "ag-grid-angular";
@Component({
selector: '',
template: `<input type="checkbox" [(ngModel)]="checkboxValue">`,
})
export class ChekboxEditorComponent implements ICellEditorAngularComp {
private params: any;
private checkboxValue:boolean;
agInit(params: any): void {
this.params = params;
this.checkboxValue = this.params.value;
}
refresh(params):boolean{
return true;
}
getValue(){
return this.checkboxValue;
}
}
最后一件事:
editable: (params)=>{return params.node.data.checkbox != true}
这里有一个逻辑可以禁用column 中true 值的编辑模式
【讨论】: