Chr*_*mer 12 ag-grid ag-grid-ng2 angular
我在Angular项目中有一个简单的ag-grid,并希望禁用其中一列中的单元格选择.在选择期间简单地删除默认的蓝色轮廓也没问题.当用户在其中单击时,我只是不希望对单元格进行可视化更改.我怎样才能做到这一点?
我看到它ColDef
有一个有用的属性suppressNavigable
,因为它不允许使用tab键选择单元格,但它仍然允许通过单击进行选择.此外,网格本身似乎提供suppressCellSelection
但它看起来不够精细,似乎不会影响任何东西.
那么,我该如何删除这个蓝色边框单元格选择?
这是我对这些列定义的代码:
this.columnDefs = [
{ headerName: 'One', field: 'one' },
{ headerName: 'Two', field: 'two' },
{
// I want to disable selection of cells in this column
headerName: 'I want no cell selection!',
field: 'three',
suppressNavigable: true,
editable: false,
}
];
Run Code Online (Sandbox Code Playgroud)
这是我用来测试的stackblitz示例:https://stackblitz.com/edit/aggrid-want-to-disable-cell-selection
Par*_*osh 21
请注意,如果我们设置,
gridOption.suppressCellSelection = true
我们可以禁用所有列单元格的单元格选择.这里的问题是关于选择时不显示特定列的单元格突出显示的边框.
你可以通过CSS和cellClass
属性来实现这一点ColDef
.
您需要在CSS下面添加.
.ag-cell-focus,.ag-cell-no-focus{
border:none !important;
}
/* This CSS is to not apply the border for the column having 'no-border' class */
.no-border.ag-cell:focus{
border:none !important;
outline: none;
}
Run Code Online (Sandbox Code Playgroud)
并使用相同的类cellClass
中ColDef
suppressNavigable: true,
cellClass: 'no-border'
Run Code Online (Sandbox Code Playgroud)
实例:aggrid-want-to-disable-cell-selection
这不会显示您甚至使用鼠标单击聚焦的单元格的边框.
小智 8
我建议suppressCellSelection
在gridOptions中使用该选项.CSS快速修复不是我建议的.
this.gridOptions = {
// Your grid options here....
suppressCellSelection: true
};
Run Code Online (Sandbox Code Playgroud)
你可以尝试这个CSS hack。不需要自定义标志。
.ag-cell-focus, .ag-cell {
border: none !important;
}
Run Code Online (Sandbox Code Playgroud)
示例 - https://stackblitz.com/edit/aggrid-want-to-disable-cell-selection-answer?file=src%2Fstyles.css
您还可以使用cellStyle
动态删除选择。这是一个例子:
{
headerName: "Is Selectable",
cellStyle: (params) => {
if (!params.value) {
return { border: "none" };
}
return null;
},
...
},
{
headerName: "UnSelectable",
cellStyle: { border: "none" },
...
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12881 次 |
最近记录: |