@equinor/fusion-framework-module-ag-grid

中文文档
37.2.0发布于 2026/11/12ISCTypeScriptES Module零依赖近 30 天下载 5065

Fusion module for using AG Grid

原始使用文档
文档目录15 节
  1. When to use this package
  2. Installation
  3. Quick start
  4. Theming
  5. Customizing a grid instance
  6. Registering AG Grid feature modules
  7. Key exports
  8. API reference
  9. enableAgGrid(configurator, callback?)
  10. Theme inheritance
  11. Legacy add() compatibility telemetry
  12. Testing
  13. Migration from AG Grid 32 to 33
  14. Imports
  15. Modules

AG Grid Module for Fusion Framework

@equinor/fusion-framework-module-ag-grid provides a Fusion module that wraps AG Grid with centralised license-key management, theming, and module registration. It ensures every Fusion portal and application uses a consistent AG Grid setup.

When to use this package

  • Portal hosts — configure the AG Grid license key and default theme once so all child applications inherit them.
  • Applications — register the specific AG Grid feature modules (row models, toolpanels, export, etc.) needed by each app to keep bundles small via tree-shaking.

[!TIP] This is the base package. Both ag-grid-community and ag-grid-enterprise are required peer dependencies. For React-specific hooks and components see @equinor/fusion-framework-react-ag-grid.

Installation

pnpm add @equinor/fusion-framework-module-ag-grid

[!WARNING] Fusion will try to keep the semantic major and minor versions in sync with AG Grid, but there might be cases where this is not possible. So @equinor/fusion-framework-module-ag-grid and ag-grid might have different patch versions.

[!IMPORTANT] v35 Breaking Change: AG Charts has been moved to a separate package @equinor/fusion-framework-react-ag-charts. If you need integrated charting, install both packages and use IntegratedChartsModule.with(AgChartsEnterpriseModule).

Before upgrading to AG Grid 33, remove all previous references to @equinor/fusion-react-ag-grid-styles, @ag-grid-community/* and @ag-grid-enterprise/* from your project dependencies.

Quick start

Register the module in your portal or application configurator with enableAgGrid:

import { type FrameworkConfigurator } from '@equinor/fusion-framework';
import { enableAgGrid } from '@equinor/fusion-framework-module-ag-grid';

export async function configure(config: FrameworkConfigurator) {
    enableAgGrid(config, (builder) => {
        builder.setLicenseKey('your-license-key');
    });
}

The enableAgGrid helper accepts an optional callback that receives an IAgGridConfigurator builder. Use it to set the license key, theme, and feature modules.

Theming

This module uses the alpine theme as the base theme for AG Grid. The theme can be customized by providing a custom theme in the application.

[!TIP] AG Grid has a theme builder that can be used to preview and generate a custom theme.

enableAgGrid(configurator, (builder) => {
    builder.setTheme((theme) => {
        return theme.withParams({
            backgroundColor: "#1f2836",
            browserColorScheme: "dark",
            chromeBackgroundColor: {
                ref: "foregroundColor",
                mix: 0.07,
                onto: "backgroundColor"
            },
            foregroundColor: "#FFF",
            headerFontSize: 14
        });
    });
});

[!IMPORTANT] Themes are by default inherited from parent scopes (aka portals). This means that the theme set in the portal will be inherited by the application.

NOTE: Configured themes are global and will affect all instances of AG Grid in the application.

Customizing a grid instance

The module provides a hook to customize a grid instance.

import { useTheme } from '@equinor/fusion-framework-react-ag-grid';

const MyComponent = () => {
    const baseTheme = useTheme();
    const [hasError, setHasError] = useState(false);
    const theme = useMemo(() => baseTheme.withParams({
        // add red text color if error
        cellTextColor: hasError ? "#FF0000" : baseTheme.cellTextColor,
    }), [baseTheme, hasError]);

    return (
        <AgGridReact
            theme={theme}
            ...
        />
    );
};

Registering AG Grid feature modules

Since AG Grid 33, feature modules must be explicitly registered so tree-shaking can remove unused code. Use builder.addModule() or builder.setModules() inside the enableAgGrid callback:

import { enableAgGrid } from '@equinor/fusion-framework-module-ag-grid';
import { ClientSideRowModelModule } from 'ag-grid-community';
import {
    ClipboardModule,
    ColumnsToolPanelModule,
    ExcelExportModule,
    FiltersToolPanelModule,
    MenuModule,
} from 'ag-grid-enterprise';

export const configure: AppModuleInitiator = (configurator, { env }) => {
    enableAgGrid(configurator, (builder) => {
        builder.setModules([
            ClientSideRowModelModule,
            ClipboardModule,
            ColumnsToolPanelModule,
            ExcelExportModule,
            FiltersToolPanelModule,
            MenuModule,
        ]);
    });
};

[!IMPORTANT] Modules must be registered in configuration to enable proper tree-shaking. Only import what you need.

Key exports

ExportPurpose
enableAgGridRegister the AG Grid module with a Fusion configurator
AgGridConfiguratorConfiguration builder (license key, theme, modules)
AgGridProviderRuntime provider exposing the resolved config
fusionThemeDefault Equinor-branded AG Grid theme (from ./themes)
createThemeFromThemeClone a theme to avoid cross-context instanceof issues (from ./themes)

API reference

enableAgGrid(configurator, callback?)

Registers the AG Grid module. The optional callback receives an IAgGridConfigurator:

  • setLicenseKey(key) — set the enterprise license key
  • setTheme(theme | callback | null) — set, customise, or clear the global theme
  • setModules(modules) — replace all registered AG Grid modules
  • addModule(module) — append a single module
  • removeModule(module | name) — remove a module by reference or name

Theme inheritance

Themes configured in a parent scope (portal) are automatically inherited by child scopes (applications). The module clones inherited themes via createThemeFromTheme to avoid instanceof mismatches across module-federation boundaries.

Legacy add() compatibility telemetry

IAgGridProvider extends TelemetryConnectable. The provider obtains its shared handle through telemetry.scope('ag-grid'), with a lazy factory fallback for older custom providers, for the existing notification, and disconnects it on teardown. The shim and its one-notification observation budget are unchanged.

The provider patches a legacy Set-style add() onto AG Grid's shared Map-shaped agStyleInjectionState.grids when it is missing, so bundles built for older AG Grid keep working. When the host has the telemetry module, the first call to that patched add() in each host lifecycle emits one fusion.ag-grid.legacy-add event at Warning level, with the standard operational diagnostic envelope. Installing the patch alone records nothing.

The event contains no grid keys, DOM references or theme data, and the patched add() keeps its behavior: it sets the key to true and returns the map, even if telemetry fails. Without telemetry, or after the module is disposed, nothing is recorded. Use the event to find hosts that still rely on the legacy shape before the shim is removed. A page whose patch was installed by an older Fusion AG Grid version cannot be observed.

Testing

Without a license key, AG Grid Enterprise logs a "License Key Not Found" banner through console.error on every grid mount, which is expected in tests but buries real assertion failures in the reporter output. Call suppressAgGridLicenseBanner once from your test setup file to filter just that banner:

// src/test/setupTests.ts
import { suppressAgGridLicenseBanner } from '@equinor/fusion-framework-module-ag-grid/testing';

suppressAgGridLicenseBanner();

[!TIP] This only hides the banner in tests. To remove it from a running application, configure a real license key via enableAgGrid/setLicenseKey instead.

Migration from AG Grid 32 to 33

AG Grid 33 consolidated all feature modules into single ag-grid-community and ag-grid-enterprise packages. Key changes:

  • Remove all @ag-grid-community/* and @ag-grid-enterprise/* dependencies
  • Remove @equinor/fusion-react-ag-grid-styles — styles are bundled in v33+
  • Register feature modules explicitly via builder.setModules() for correct tree-shaking

[!IMPORTANT] Read the AG Grid v33 changelog before upgrading. Additionally, developers should also refer to the official AG Grid upgrade guide available at Upgrading to AG Grid 33 for comprehensive details and best practices.

Imports

Remove the following imports:

  • @ag-grid-community/*
  • @ag-grid-enterprise/*

Replace with:

  • @equinor/fusion-framework-module-ag-grid

Modules

Since AG Grid 33, all modules have been aggregated into a single package, which means the modules need to be defined in the application configuration.

Move all ModuleRegistry.registerModules to builder.setModules in the application configuration.

// my-app/src/app.ts
- import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
- import { ColumnsToolPanelModule } from '@ag-grid-enterprise/column-tool-panel';
- import { FiltersToolPanelModule } from '@ag-grid-enterprise/filter-tool-panel';
- import { MenuModule } from '@ag-grid-enterprise/menu';
- import { ExcelExportModule } from '@ag-grid-enterprise/excel-export';
- import { ClipboardModule } from '@ag-grid-enterprise/clipboard';
- import { RangeSelectionModule } from '@ag-grid-enterprise/range-selection';

- ModuleRegistry.registerModules([
-     ClientSideRowModelModule,
-     ColumnsToolPanelModule,
-     FiltersToolPanelModule,
-     MenuModule,
-     ExcelExportModule,
-     RangeSelectionModule,
-     ClipboardModule,
- ]);
// config.ts
+ import { enableAgGrid } from '@equinor/fusion-framework-module-ag-grid';
+ import { ClientSideRowModelModule } from '@equinor/fusion-framework-module-ag-grid/community';
+ import {
+     ClipboardModule,
+     ColumnsToolPanelModule,
+     ExcelExportModule,
+     FiltersToolPanelModule,
+     MenuModule,
+ } from '@equinor/fusion-framework-module-ag-grid/enterprise';
  
  export const configure: AppModuleInitiator = (configurator, { env }) => {
+    enableAgGrid(configurator, (builder) => {
+        builder.addModules([
+            ClientSideRowModelModule,
+            ClipboardModule,
+            ColumnsToolPanelModule,
+            ExcelExportModule,
+            FiltersToolPanelModule,
+            MenuModule,
+        ]);
+    });
  };

版本与发布记录

@equinor/fusion-framework-module-ag-grid 共发布 133 个版本,首次发布于 2022/06/23;过去 12 个月发布了 27 个版本。

版本发布日期距今
37.2.0latest2026/11/121 天前
37.2.0-next.1next2026/11/112 天前
37.2.0-next.02026/10/2816 天前
37.1.42026/10/1727 天前
37.1.4-trusted-publishing-20261015-9dfe7602cd2a49a8a9df00d62c26e7304a82a85atrusted-publishing-202610152026/10/1629 天前
37.1.32026/10/121 个月前

其他发布通道:apploader → 34.0.3-apploader-be21a6b60eb13eee8bf869e75002d8634e9c50a9,preview → 34.2.2-preview.3,cli-search-index → 34.2.3-cli-search-index.0,msal-v5 → 34.4.1-msal-v5.0,trusted-publishing-20261015 → 37.1.4-trusted-publishing-20261015-9dfe7602cd2a49a8a9df00d62c26e7304a82a85a,next → 37.2.0-next.1。

关于 @equinor/fusion-framework-module-ag-grid 的常见问题

@equinor/fusion-framework-module-ag-grid 是什么?

Fusion module for using AG Grid

如何安装 @equinor/fusion-framework-module-ag-grid?

在项目目录运行 npm install @equinor/fusion-framework-module-ag-grid,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ag-grid-community(>=36.0.0)、ag-grid-enterprise(>=36.0.0)、@equinor/eds-tokens(^2.0.0)、@equinor/fusion-framework-module(^6.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@equinor/fusion-framework-module-ag-grid 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@equinor/fusion-framework-module-ag-grid 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@equinor/fusion-framework-module-ag-grid 可以商用吗?

@equinor/fusion-framework-module-ag-grid 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@equinor/fusion-framework-module-ag-grid 的下载量有多少?

根据 npm 官方下载统计,@equinor/fusion-framework-module-ag-grid 在 2026/10/14 – 2026/11/12 这 30 天内被下载 5,065 次,日均约 169 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@equinor/fusion-framework-module-ag-grid 还在维护吗?

最新版本 37.2.0 发布于 2026/11/12(1 天前);至今共发布 133 个版本,其中过去 12 个月发布了 27 个;首次发布于 2022/06/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。