简体   繁体   English

ag-Grid 使用 CSS 自定义工具提示

[英]ag-Grid customize tooltip using CSS

I was wondering whether there is a way to customize the built-in tooltip and the header tooltip using CSS?我想知道是否有办法使用 CSS 自定义内置工具提示和 header 工具提示? Is there a class name that can be referenced?有没有可以引用的 class 名称?

Yes, there is a class called ag-tooltip in ag-grid.css是的,在 ag-grid.css 中有一个叫做 ag-tooltip 的类

I'm able to customized the default headerTooltip, something like below:我可以自定义默认的 headerTooltip,如下所示:

.ag-tooltip{
   background-color: #0f1014;
   color: #999eab;
   border-radius: 2px;
   padding: 5px;
   border-width: 1px;
   border-style: solid;
   border-color: #545454;
}

In case you want to customize tooltip using a 3rd party library, you can make use of cell renderer component.如果您想使用 3rd 方库自定义工具提示,您可以使用单元渲染器组件。
Here is an example using angular cell renderer component and ngx-bootstrap.这是一个使用角度单元渲染器组件和 ngx-bootstrap 的示例。

@Component({
    selector: 'tooltip-cell',
    template: `<span tooltip="Custom text" container="body">{{params.value}}</span>`,
})
export class ToolTipRenderer implements ICellRendererAngularComp {
    public params: any;

    agInit(params: any): void {
        this.params = params;
    }

    refresh(): boolean {
        return false;
    }
}

Once created, you can register the custom cell renderer component using frameworkComponents gridOption.创建后,您可以使用 frameworkComponents gridOption 注册自定义单元格渲染器组件。 You can more details in the official doc here and more details on Cell Renderer Components您可以在此处的官方文档中了解更多详细信息以及有关Cell Renderer Components 的更多详细信息

I used "Balham" theme in my code and I had to override the default tooltip CSS.我在我的代码中使用了“Balham”主题,我不得不覆盖默认的工具提示 CSS。

I made a file with the custom CSS.我使用自定义 CSS 制作了一个文件。

.ag-theme-balham .ag-tooltip {
  background-color: black;
  color: white;
  border-radius: 2px;
  padding: 10px 16px;
  border-width: 1px;
  border-style: solid;
  border-color: #cbd0d3;
  transition: opacity 1s;
}

Finally, I imported the CSS file where I had implemented the Ag-Grid.最后,我导入了实现 Ag-Grid 的 CSS 文件。

import "./customTooltipStyle.css";

This worked for me.这对我有用。

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

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