简体   繁体   English

如何 select 列在 ag-grid

[英]How to select column in ag-grid

I an using Ag-Grid.我使用 Ag-Grid。

I want to select column horizontal and vertical like under picture.我想像下图一样将 select 列水平和垂直。

How to solution??怎么解决??

在此处输入图像描述

I think you would have to do this manually.我认为您必须手动执行此操作。 You could watch for cell selection yourself, and then keep track of the selected column.您可以自己观察单元格选择,然后跟踪所选列。 Then you could use cellStyle in the column definition params to set the background color when the column is selected.然后,您可以在列定义参数中使用cellStyle来设置选择列时的背景颜色。 You have to redraw the rows, since the cellStyle function only gets run when the rows are drawn.您必须重新绘制行,因为cellStyle function 仅在绘制行时运行。 For example:例如:

onCellFocused: function(params) {
    if (params.column) {
        selectedColumn = params.column.colDef;
        params.api.redrawRows();
    }
},
defaultColDef: {
    cellStyle: function(params) {
        if (params.colDef === selectedColumn) {
            return {'background-color': '#b7e4ff'};
        }
    }
}

Unfortunately, it looks like redrawing the rows clears the selection, so you either have to reselect the row manually, or use a row style.不幸的是,重绘行似乎会清除选择,因此您要么必须手动重新选择行,要么使用行样式。

Check it out here: https://stackblitz.com/edit/ag-grid-select-column?embed=1&file=index.js在这里查看: https://stackblitz.com/edit/ag-grid-select-column?embed=1&file=index.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM