【发布时间】:2018-11-13 08:21:57
【问题描述】:
我在网站上使用 AG Grid。当用户单击一个单元格时,它会获得焦点并获得一个蓝色轮廓。
当用户点击网站上的某些其他元素时,我需要移除此焦点,但我不知道该怎么做。是否有为此设置的方法或属性?
【问题讨论】:
标签: javascript focus ag-grid
我在网站上使用 AG Grid。当用户单击一个单元格时,它会获得焦点并获得一个蓝色轮廓。
当用户点击网站上的某些其他元素时,我需要移除此焦点,但我不知道该怎么做。是否有为此设置的方法或属性?
【问题讨论】:
标签: javascript focus ag-grid
将以下 sn-p 添加到您的 css 中
.ag-cell-focus, .ag-cell {
border: none !important;
}
【讨论】:
Angular2+ DEMO
ngAfterViewInit(){
let body = document.body;
body.addEventListener("mouseup", (e) => {
let container = this.agGrid._nativeElement;
if (!container.contains(e.target))
{
this.gridApi.clearFocusedCell();
}
})
}
JavaScript DEMO
var body = document.body;
body.addEventListener("mouseup", (e) => {
let gridDiv = document.querySelector('#myGrid')
if (!gridDiv.contains(e.target))
{
gridOptions.api.clearFocusedCell();
}
})
【讨论】:
const body = document.body; body.addEventListener('mouseup', (e) => { const container = this.commonAgGrid.nativeElement; if (!container.contains(e.target)) { this.gridApi.clearFocusedCell(); } });