const files = [
{
id: "alpha",
path: ['Alpha'],
},
{
id: "row-group-0-Beta",
path: ['Beta'],
subtotal: true,
},
{
id: "row-group-0-Beta-1-Category 1",
path: ['Beta', 'Category 1'],
subtotal: true,
},
{
id: "subcategory-1-1",
path: ['Beta', 'Category 1', 'Subcategory 1-1'],
},
{
id: "subcategory-1-2",
path: ['Beta', 'Category 1', 'Subcategory 1-2'],
},
{
id: "subcategory-1-3",
path: ['Beta', 'Category 1', 'Subcategory 1-3'],
},
{
id: "row-group-0-Beta-1-Category 2",
path: ['Beta', 'Category 2'],
subtotal: true,
},
{
id: "subcategory-2-1",
path: ['Beta', 'Category 2', 'Subcategory 2-1'],
},
{
id: "subcategory-2-2",
path: ['Beta', 'Category 2', 'Subcategory 2-2'],
},
{
id: "subcategory-2-3",
path: ['Beta', 'Category 2', 'Subcategory 2-3'],
},
{
id: "total",
path: ['Total'],
},
];
export function getChartsInitial() {
const result = {};
for (let i = 0; i < files.length; i++) {
result[files[i].id] = [{x: new Date(), y: i}];
}
return result;
}
export function getRows() {
return files.filter((item) => item.subtotal !== true);
}
import '@angular/compiler';
import { provideHttpClient } from '@angular/common/http';
import { enableProdMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
if ((window as any).ENABLE_PROD_MODE) {
enableProdMode();
}
const app = bootstrapApplication(AppComponent, {
providers: [provideHttpClient()],
});
/** TEAR DOWN START **/
app.then((appRef) => {
(window as any).tearDownExample = () => appRef.destroy();
}).catch((err) => {
console.error('Error during bootstrap:', err);
});
/** TEAR DOWN END **/
import { Component } from '@angular/core';
import { AgGridAngular } from 'ag-grid-angular';
import {
ClientSideRowModelApiModule,
ClientSideRowModelModule,
ColDef,
GetDataPath,
GetRowIdFunc,
GetRowIdParams,
GridApi,
HighlightChangesModule,
ModuleRegistry,
RenderApiModule,
RowApiModule,
} from 'ag-grid-community';
import { TreeDataModule, SparklinesModule } from 'ag-grid-enterprise';
import {
AgChartsCommunityModule,
AgSparklineOptions,
} from "ag-charts-community";
import { getChartsInitial, getRows } from './data';
ModuleRegistry.registerModules([
ClientSideRowModelApiModule,
ClientSideRowModelModule,
HighlightChangesModule,
TreeDataModule,
RenderApiModule,
RowApiModule,
SparklinesModule.with(AgChartsCommunityModule),
]);
@Component({
selector: 'my-app',
standalone: true,
imports: [AgGridAngular],
template: `
<h1>Example full RxJS</h1>
<ag-grid-angular
style="width: 100%; height: 100%;"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
[autoGroupColumnDef]="autoGroupColumnDef"
[rowData]="rowData"
[treeData]="true"
[groupDefaultExpanded]="groupDefaultExpanded"
[getDataPath]="getDataPath"
[animateRows]="true"
(gridReady)="onGridReady($event)"
[getRowId]="getRowId"
/> `,
})
export class AppComponent {
private api!: GridApi;
columnDefs: ColDef[] = [
{
field: "chart",
cellRenderer: "agSparklineCellRenderer",
cellRendererParams: {
sparklineOptions: {
type: "bar",
xKey: "x",
yKey: "y",
} as AgSparklineOptions,
},
valueGetter: (params): { x: Date; y: number; }[] => {
return this.chartData[params.node.id] ?? [];
},
},
{
field: "empty"
}
];
defaultColDef: ColDef = {
flex: 1,
enableCellChangeFlash: true,
};
autoGroupColumnDef: ColDef = {
minWidth: 250,
cellRendererParams: {
suppressCount: true,
},
};
groupDefaultExpanded = -1;
getDataPath: GetDataPath = (data) => data.path;
getRowId: GetRowIdFunc = (params: GetRowIdParams) => {
return params.data.id;
};
rowData: any[] = getRows();
chartData: Record<string, { x: Date; y: number;}[]> = getChartsInitial();
// {[row_id: string]: { x: Date; y: number;}[]}
gridApi = undefined;
constructor() {
setInterval(
() => {
// Append new bar.
for (const i in this.chartData) {
this.chartData[i].push({
x: new Date(),
y: Math.ceil(Math.random() * 10 % 9) + 1,
})
}
// Refresh cells.
const groups = []
this.gridApi.forEachNode(
(rowNode, index) => {
if (rowNode.group === true) {
groups.push(rowNode);
}
}
);
this.gridApi.refreshCells({
force: true,
columns: ["chart"],
//rowNodes: groups,
});
// Update data and refresh.
// this.gridApi.applyTransactionAsync(
// {
// add: [],
// update: [
// ...this.rowData,
// ],
// remove: [],
// },
// () => {
// // Collect group nodes.
// const groups = []
// this.gridApi.forEachNode(
// (rowNode, index) => {
// if (rowNode.group === true) {
// groups.push(rowNode);
// }
// }
// );
// this.gridApi.refreshCells({
// force: true,
// columns: ["chart"],
// rowNodes: groups,
// });
// },
// );
},
2000,
);
}
public onGridReady(params): void {
this.gridApi = params.api;
}
}
if (typeof window !== 'undefined') {
var waitSeconds = 100;
var head = document.getElementsByTagName('head')[0];
var isWebkit = !!window.navigator.userAgent.match(/AppleWebKit\/([^ ;]*)/);
var webkitLoadCheck = function (link, callback) {
setTimeout(function () {
for (var i = 0; i < document.styleSheets.length; i++) {
var sheet = document.styleSheets[i];
if (sheet.href == link.href) {
return callback();
}
}
webkitLoadCheck(link, callback);
}, 10);
};
var cssIsReloadable = function cssIsReloadable(links) {
// Css loaded on the page initially should be skipped by the first
// systemjs load, and marked for reload
var reloadable = true;
forEach(links, function (link) {
if (!link.hasAttribute('data-systemjs-css')) {
reloadable = false;
link.setAttribute('data-systemjs-css', '');
}
});
return reloadable;
};
var findExistingCSS = function findExistingCSS(url) {
// Search for existing link to reload
var links = head.getElementsByTagName('link');
return filter(links, function (link) {
return link.href === url;
});
};
var noop = function () {};
var loadCSS = function (url, existingLinks) {
const stylesUrl = url.includes('styles.css') || url.includes('style.css');
return new Promise((outerResolve, outerReject) => {
setTimeout(
() => {
new Promise(function (resolve, reject) {
var timeout = setTimeout(function () {
reject('Unable to load CSS');
}, waitSeconds * 1000);
var _callback = function (error) {
clearTimeout(timeout);
link.onload = link.onerror = noop;
setTimeout(function () {
if (error) {
reject(error);
outerReject(error);
} else {
resolve('');
outerResolve('');
}
}, 7);
};
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = url;
link.setAttribute('data-systemjs-css', '');
if (!isWebkit) {
link.onload = function () {
_callback();
};
} else {
webkitLoadCheck(link, _callback);
}
link.onerror = function (event) {
_callback(event.error || new Error('Error loading CSS file.'));
};
if (existingLinks.length) {
head.insertBefore(link, existingLinks[0]);
} else {
head.appendChild(link);
}
})
// Remove the old link regardless of loading outcome
.then(
function (result) {
forEach(existingLinks, function (link) {
link.parentElement.removeChild(link);
});
return result;
},
function (err) {
forEach(existingLinks, function (link) {
link.parentElement.removeChild(link);
});
throw err;
}
);
},
stylesUrl ? 5 : 0
);
});
};
exports.fetch = function (load) {
// dont reload styles loaded in the head
var links = findExistingCSS(load.address);
if (!cssIsReloadable(links)) {
return '';
}
return loadCSS(load.address, links);
};
} else {
var builderPromise;
function getBuilder(loader) {
if (builderPromise) {
return builderPromise;
}
return (builderPromise = System['import']('./css-plugin-base.js', module.id).then(function (CSSPluginBase) {
return new CSSPluginBase(function compile(source, address) {
return {
css: source,
map: null,
moduleSource: null,
moduleFormat: null,
};
});
}));
}
exports.cssPlugin = true;
exports.fetch = function (load, fetch) {
if (!this.builder) {
return '';
}
return fetch(load);
};
exports.translate = function (load, opts) {
if (!this.builder) {
return '';
}
var loader = this;
return getBuilder(loader).then(function (builder) {
return builder.translate.call(loader, load, opts);
});
};
exports.instantiate = function (load, opts) {
if (!this.builder) {
return;
}
var loader = this;
return getBuilder(loader).then(function (builder) {
return builder.instantiate.call(loader, load, opts);
});
};
exports.bundle = function (loads, compileOpts, outputOpts) {
var loader = this;
return getBuilder(loader).then(function (builder) {
return builder.bundle.call(loader, loads, compileOpts, outputOpts);
});
};
exports.listAssets = function (loads, opts) {
var loader = this;
return getBuilder(loader).then(function (builder) {
return builder.listAssets.call(loader, loads, opts);
});
};
}
// Because IE8?
function filter(arrayLike, func) {
var arr = [];
forEach(arrayLike, function (item) {
if (func(item)) {
arr.push(item);
}
});
return arr;
}
// Because IE8?
function forEach(arrayLike, func) {
for (var i = 0; i < arrayLike.length; i++) {
func(arrayLike[i]);
}
}
(function (global) {
const urlParams = new URLSearchParams(window.location.search);
const config = {
version: urlParams.get('version') ?? '20.0.0',
prod: urlParams.get('prod') === 'false' ? false : urlParams.get('prod') ?? true,
};
process = { env: { NODE_ENV: 'development' } };
var ANGULAR_VERSION = config.version;
window.ENABLE_PROD_MODE = config.prod;
System.config({
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'ts',
typescriptOptions: {
target: 'es2020',
emitDecoratorMetadata: true,
experimentalDecorators: true,
},
meta: {
typescript: {
exports: 'ts',
},
'*.css': { loader: 'css' },
},
paths: {
// paths serve as alias
'npm:': 'https://cdn.jsdelivr.net/npm/',
...systemJsPaths,
},
// map tells the System loader where to look for things
map: {
'@angular/compiler': 'npm:@angular/compiler@' + ANGULAR_VERSION + '/fesm2022/compiler.mjs',
'@angular/platform-browser-dynamic':
'npm:@angular/platform-browser-dynamic@' + ANGULAR_VERSION + '/fesm2022/platform-browser-dynamic.mjs',
'@angular/core': 'npm:@angular/core@' + ANGULAR_VERSION + '/fesm2022/core.mjs',
'@angular/core/primitives/di': 'npm:@angular/core@' + ANGULAR_VERSION + '/fesm2022/primitives/di.mjs',
'@angular/core/primitives/signals':
'npm:@angular/core@' + ANGULAR_VERSION + '/fesm2022/primitives/signals.mjs',
'@angular/core/primitives/event-dispatch':
'npm:@angular/core@' + ANGULAR_VERSION + '/fesm2022/primitives/event-dispatch.mjs',
'@angular/common': 'npm:@angular/common@' + ANGULAR_VERSION + '/fesm2022/common.mjs',
'@angular/common/http': 'npm:@angular/common@' + ANGULAR_VERSION + '/fesm2022/http.mjs',
'@angular/platform-browser':
'npm:@angular/platform-browser@' + ANGULAR_VERSION + '/fesm2022/platform-browser.mjs',
'@angular/platform-browser/animations':
'npm:@angular/platform-browser@' + ANGULAR_VERSION + '/fesm2022/animations.mjs',
'@angular/forms': 'npm:@angular/forms@' + ANGULAR_VERSION + '/fesm2022/forms.mjs',
'@angular/animations': 'npm:@angular/animations@' + ANGULAR_VERSION + '/fesm2022/animations.mjs',
'@angular/animations/browser': 'npm:@angular/animations@' + ANGULAR_VERSION + '/fesm2022/browser.mjs',
rxjs: 'https://cdn.jsdelivr.net/npm/rxjs@7.8.1/+esm',
'rxjs/operators': 'https://cdn.jsdelivr.net/npm/rxjs@7.8.1/+esm',
css: (boilerplatePath.length === 0 ? `./` : `${boilerplatePath}/`) + 'css.js',
ts: 'npm:plugin-typescript@8.0.0/lib/plugin.js',
tslib: 'npm:tslib@2.3.1/tslib.js',
typescript: 'npm:typescript@4.4/lib/typescript.min.js',
// our app is within the app folder, appLocation comes from index.html
app: appLocation,
...systemJsMap,
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
css: {}, // Stop css.js from defaulting to apps .ts extension
app: {
main: './main.ts',
defaultExtension: 'ts',
},
'ag-grid-community': {
main: './dist/package/main.cjs.js',
defaultExtension: 'js',
format: 'cjs',
},
'ag-grid-enterprise': {
main: './dist/package/main.cjs.js',
defaultExtension: 'js',
format: 'cjs',
},
'ag-grid-angular': {
main: './fesm2022/ag-grid-angular.mjs',
defaultExtension: 'mjs',
},
'ag-charts-core': {
defaultExtension: 'js',
format: 'cjs',
},
'ag-charts-community': {
defaultExtension: 'js',
format: 'cjs',
},
'ag-charts-enterprise': {
defaultExtension: 'js',
format: 'cjs',
},
'@ag-grid-community/locale': {
format: 'cjs',
},
},
});
window.addEventListener('error', (e) => {
console.error('ERROR', e.message, e.filename);
});
System.import(startFile).catch(function (err) {
document.body.innerHTML =
'<div class="example-error" style="background:#fdb022;padding:1rem;">' + 'Example Error: ' + err + '</div>';
console.error(err);
});
})(this);
{
"name": "ag-grid-example",
"dependencies": {
"@angular/core": "20.0.0",
"@angular/common": "20.0.0",
"@angular/forms": "20.0.0",
"@angular/platform-browser": "20.0.0",
"ag-grid-angular": "34.3.1",
"ag-grid-community": "34.3.1",
"ag-grid-enterprise": "34.3.1",
"rxjs": "^7.8.1",
"tslib": "2.6.3"
},
"devDependencies": {
"@types/node": "^22",
"typescript": "^4.6.2"
}
}
<!doctype html>
<html lang="en">
<head>
<title>Angular Example - Tree Data - Kitchen Sink</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="noindex" />
<link
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;700&display=swap"
rel="stylesheet"
/>
<style media="only screen">
:root,
body,
my-app {
height: 100%;
width: 100%;
margin: 0;
box-sizing: border-box;
-webkit-overflow-scrolling: touch;
}
html {
position: absolute;
top: 0;
left: 0;
padding: 0;
overflow: auto;
font-family: -apple-system, "system-ui", "Segoe UI", Roboto,
"Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif,
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
"Noto Color Emoji";
}
body {
padding: 16px;
overflow: auto;
background-color: transparent;
}
</style>
</head>
<body>
<my-app></my-app>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<script src="https://cdn.jsdelivr.net/npm/core-js-bundle@3.6.5/minified.js"></script>
<script src="https://cdn.jsdelivr.net/npm/zone.js@0.14.3/bundles/zone.umd.min.js"></script>
<script>
var appLocation = "";
var boilerplatePath = "";
var startFile = "main.ts";
var systemJsMap = {
"@ag-grid-community/styles":
"https://cdn.jsdelivr.net/npm/@ag-grid-community/styles@34.3.1",
"ag-grid-angular":
"https://cdn.jsdelivr.net/npm/ag-grid-angular@34.3.1/",
"ag-grid-community":
"https://cdn.jsdelivr.net/npm/ag-grid-community@34.3.1",
"ag-grid-enterprise":
"https://cdn.jsdelivr.net/npm/ag-grid-enterprise@34.3.1/",
};
var systemJsPaths = {
"@ag-grid-community/locale":
"https://cdn.jsdelivr.net/npm/@ag-grid-community/locale@34.3.1/dist/package/main.cjs.js",
"ag-charts-community":
"https://cdn.jsdelivr.net/npm/ag-charts-community@12.3.1/dist/package/main.cjs.js",
"ag-charts-core":
"https://cdn.jsdelivr.net/npm/ag-charts-core@12.3.1/dist/package/main.cjs.js",
"ag-charts-enterprise":
"https://cdn.jsdelivr.net/npm/ag-charts-enterprise@12.3.1/dist/package/main.cjs.js",
"ag-charts-types":
"https://cdn.jsdelivr.net/npm/ag-charts-types@12.3.1/",
};
</script>
<script src="https://cdn.jsdelivr.net/npm/systemjs@0.21.6/dist/system.js"></script>
<script src="systemjs.config.js"></script>
</body>
</html>