【问题标题】:How to disable entire column in ag-grid如何禁用 ag-grid 中的整个列
【发布时间】:2019-04-16 01:32:58
【问题描述】:

我想根据列包含 onCellClicked 事件的特定条件禁用整个列,但我不希望它触发

【问题讨论】:

标签: angularjs ag-grid


【解决方案1】:

使用gridOptions.isRowSelectable,我们可以将特定行设置为可选择或不可选择。下面是来自 ag-grid 文档本身的示例。 gridOptions.isRowSelectable: function(rowNode) { return rowNode.data ? rowNode.data.year < 2007 : false; }

【讨论】:

  • 他说的是column,而不是row
  • 他评论说他使用了 rowSelection 倍数,所以我认为这是行选择。感谢您提及它@un.spike
【解决方案2】:

您必须在colDef 中定义editable 属性

editable: false <-- edit would be disabled for needed column

更新

标题复选框可用于行选择,对于其他事情,您应该自己创建自定义处理程序。

对于显示处理,您需要创建cellRenderer

对于编辑处理,您需要创建自己的cellEditor

基于official demo:

这是您案例的工作示例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)=&gt;{return params.node.data.checkbox != true}

这里有一个逻辑可以禁用columntrue 值的编辑模式

【讨论】:

  • 感谢您的回答。但我在列中使用了 rowSelection: 'multiple' 并希望禁用整个列。
  • 这里是 plunker [plnkr.co/edit/FKzYGZd5rbUVKv1j5yQK?p=preview] 我希望当网格加载和复选框被选中时(基于某些条件)我希望第一列禁用所以复选框不会被选中或取消选中。
  • 我想实现以下 1.加载带有复选框的网格(根据某些条件预先选择了一些复选框) 2.用户无法选择/取消选择复选框,就像他们只有查看权限而不是编辑权限
猜你喜欢
  • 2017-10-25
  • 2022-01-15
  • 2021-04-05
  • 2021-01-08
  • 2020-08-19
  • 2021-03-22
  • 2018-08-29
  • 2021-09-11
  • 2018-11-24
相关资源
最近更新 更多