简体   繁体   English

定制的 CSS 样式不适用于 ag-grid

[英]Customized CSS Style Not Working for ag-grid

Seems pretty basic, but the documentation is scant .看起来很基本,但文档很少

Creating a module override CSS, I have tried to customize line-height for one of my tables so that text does not double-space when text wrapping.创建一个模块覆盖 CSS,我尝试为我的一个表自定义行高,以便在文本换行时文本不会双倍空格。

Here is the CSS, Test.module.css :这是 CSS, Test.module.css

.ag-theme-alpine .ag-cell, .ag-theme-alpine .ag-full-width-row .ag-cell-wrapper.ag-row-group {
    line-height: min(var(--ag-line-height,20px),20px);
  }

Here is a sample of my module, Test.tsx :这是我的模块Test.tsx的示例:

import './Test.module.css'
...
return (
        <div className="ag-theme-alpine" style={{ height: '105px', width: screenWidth }}>
          <AgGridReact rowData={testData} columnDefs={testCols} headerHeight={hiddenHeader} getRowHeight={getRowHeight} rowStyle={{width: screenWidth}} ></AgGridReact>
        </div>
)

The result?结果? Line-height remains the default (may be hard to see, but there is a second line of text below the first): Line-height 仍然是默认值(可能很难看到,但在第一行下方有第二行文本):

在此处输入图像描述

在此处输入图像描述

I have also attempted several variations on the below:我还尝试了以下几种变体:

  • .ag-theme-alpine.ag-cell { line-height: min(var(--ag-line-height,20px),20px); }
  • .ag-theme-alpine.ag-cell { line-height: 20; }
  • .ag-theme-alpine.ag-cell { --ag-line-height: '20px'; }
  • Adding !important to the end of the line, eg .ag-theme-alpine.ag-cell { line-height: 20;important; }!important添加到行尾,例如.ag-theme-alpine.ag-cell { line-height: 20;important; } .ag-theme-alpine.ag-cell { line-height: 20;important; }

Note that the variable name was found in the console, as it does not appear in the list of variable names found in the documentation .请注意,变量名称是在控制台中找到的,因为它没有出现在文档中找到的变量名称列表中。 Maybe this is the problem, but I have yet to see a variable that meets the criteria.也许这就是问题所在,但我还没有看到符合标准的变量。

Resolved this in a bit of an unexpected way.以一种意想不到的方式解决了这个问题。 Adding the below to the global style sheet overrode the default:将以下内容添加到全局样式表会覆盖默认值:

.ag-cell {
  line-height: min(var(--ag-line-height,15px),15px) !important;
}

Note that I had to change the class being referenced, paring it back to .ag-cell only.请注意,我必须更改被引用的 class,仅将其还原为.ag-cell Not sure why exactly, but this was the only thing that worked.不知道为什么,但这是唯一有效的方法。

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

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