简体   繁体   English

如何在 Ag-Grid 中仅指定一个 header 的样式?

[英]How to specify the style of just one header in an Ag-Grid?

I would like to specify the Header style of just one column on my grid.我想在我的网格上仅指定一列的 Header 样式。 I know how to configure the Header style for all columns of a specific grid.我知道如何为特定网格的所有列配置 Header 样式。 For that it's necessary to add on "styles:scss" file the following:为此,有必要在“styles:scss”文件中添加以下内容:

Example:例子:

#IdOfGrid .ag-header-cell-label {
justify-content: left;} 

How can I apply this style for just one column header?如何仅将这种样式应用于一列 header?

Thank you!谢谢!

As per https://www.ag-grid.com/javascript-grid-column-properties/根据https://www.ag-grid.com/javascript-grid-column-properties/

You can add headerClass property to your column properties and add css for that class it applies only for that column header您可以将 headerClass 属性添加到列属性中,并为该 class 添加 css 它仅适用于该列 header

Have a CSS class in headerClass property inside columnDefs like this:在 columnDefs 内的headerClass属性中有一个 CSS class ,如下所示:

columnDefs = [
{
  headerName: "Table Name",
  headerClass: "table-header",
  field: "tableName"
},
 .
 .
 .
]

In css, use ::ng-deep along with another component/class names if your ag-grid-angular component is wrapped inside different elements.在 css 中,如果您的 ag-grid-angular 组件包含在不同的元素中,请使用::ng-deep以及另一个组件/类名称。 In my case, I got the style like this:就我而言,我得到了这样的风格:

::ng-deep .main-wrapper app-custom-grid ag-grid-angular .table-header {
  background-color: blue;
}

To set column basic style, just give:要设置列基本样式,只需给出:

headerName: 'Title Here',
field:'title',
styleCss: { background: '#eee'; 'font-size': '15px' }

If you want to give style on some condition, then you need a external func, and call it inside column definition, as follows:如果要在某些条件下赋予样式,则需要一个外部函数,并在列定义中调用它,如下所示:

constructor(){
  this.gridOptions = {

    getRowStyle: (params: any) => {
      if (params.data){
        if(params.data.flag) {
          return { background: '#eee', 'font-weight': 750 };
        }
      }
    }
  }// end of gridoptions
}// end of constructor

For more detail, look deeply on my another answer: https://stackoverflow.com/a/61236065/7118138有关更多详细信息,请深入了解我的另一个答案: https://stackoverflow.com/a/61236065/7118138

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

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