Skip to content

Commit 6622d5f

Browse files
authored
Merge pull request #381 from plotly/feature/ag-grid-33
Feature: AG Grid 33
2 parents afeaeb9 + 6d908c0 commit 6622d5f

File tree

15 files changed

+353
-74
lines changed

15 files changed

+353
-74
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# Build artifacts
55
dash_ag_grid/*
66
!dash_ag_grid/__init__.py
7+
!dash_ag_grid/_version.py
8+
!dash_ag_grid/themes.py
79
R/
810
deps/
911
man/

dash_ag_grid/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@
99
# noinspection PyUnresolvedReferences
1010
from ._imports_ import *
1111
from ._imports_ import __all__
12+
from dash_ag_grid import themes
1213

1314
if not hasattr(_dash, '__plotly_dash') and not hasattr(_dash, 'development'):
1415
print('Dash was not successfully imported. '
1516
'Make sure you don\'t have a file '
1617
'named \n"dash.py" in your current directory.', file=_sys.stderr)
1718
_sys.exit(1)
1819

19-
_basepath = _os.path.dirname(__file__)
20-
_filepath = _os.path.abspath(_os.path.join(_basepath, 'package-info.json'))
21-
with open(_filepath) as f:
22-
package = json.load(f)
20+
from ._version import __version__, grid_version, get_package_info
2321

22+
package = get_package_info()
2423
package_name = package['name'].replace(' ', '_').replace('-', '_')
25-
__version__ = package['version']
26-
grid_version = package['dependencies']['ag-grid-community']
2724

2825
_current_path = _os.path.dirname(_os.path.abspath(__file__))
2926

dash_ag_grid/_version.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import json
2+
import os
3+
4+
def get_package_info():
5+
basepath = os.path.dirname(__file__)
6+
filepath = os.path.abspath(os.path.join(basepath, 'package-info.json'))
7+
with open(filepath) as f:
8+
return json.load(f)
9+
10+
package = get_package_info()
11+
__version__ = package['version']
12+
grid_version = package['dependencies']['ag-grid-community']

dash_ag_grid/themes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ._version import grid_version
2+
3+
_base_url = f"https://cdn.jsdelivr.net/npm/ag-grid-community@{grid_version}/styles"
4+
5+
BASE = f"{_base_url}/ag-grid.min.css"
6+
ALPINE = f"{_base_url}/ag-theme-alpine.min.css"
7+
BALHAM = f"{_base_url}/ag-theme-balham.min.css"
8+
MATERIAL = f"{_base_url}/ag-theme-material.min.css"
9+
QUARTZ = f"{_base_url}/ag-theme-quartz.min.css"

package-lock.json

Lines changed: 104 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dash-ag-grid",
3-
"version": "32.3.0",
3+
"version": "33.3.2rc0",
44
"description": "Dash wrapper around AG Grid, the best interactive data grid for the web.",
55
"repository": {
66
"type": "git",
@@ -32,11 +32,11 @@
3232
"dependencies": {
3333
"@emotion/react": "^11.11.3",
3434
"@emotion/styled": "^11.11.0",
35-
"ag-grid-community": "32.3.4",
36-
"ag-grid-enterprise": "32.3.4",
37-
"ag-grid-react": "32.3.4",
3835
"@mui/icons-material": "^5.15.7",
3936
"@mui/material": "^5.15.7",
37+
"ag-grid-community": "33.3.2",
38+
"ag-grid-enterprise": "33.3.2",
39+
"ag-grid-react": "33.3.2",
4040
"d3-format": "^3.1.0",
4141
"d3-time": "^3.1.0",
4242
"d3-time-format": "^4.1.0",

src/lib/components/AgGrid.react.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import PropTypes from 'prop-types';
22
import LazyLoader from '../LazyLoader';
33
import React, {lazy, Suspense, useState, useCallback, useEffect} from 'react';
4+
import {AllCommunityModule, ModuleRegistry} from 'ag-grid-community';
5+
6+
// Register all community features
7+
ModuleRegistry.registerModules([AllCommunityModule]);
48

59
const RealAgGrid = lazy(LazyLoader.agGrid);
610
const RealAgGridEnterprise = lazy(LazyLoader.agGridEnterprise);
@@ -53,7 +57,7 @@ function DashAgGrid(props) {
5357
DashAgGrid.dashRenderType = true;
5458

5559
DashAgGrid.defaultProps = {
56-
className: 'ag-theme-alpine',
60+
className: '',
5761
resetColumnState: false,
5862
exportDataAsCsv: false,
5963
selectAll: false,

src/lib/fragments/AgGrid.react.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ import RowMenuRenderer from '../renderers/rowMenuRenderer';
4646
import {customFunctions} from '../renderers/customFunctions';
4747

4848
import {AgGridReact, useGridFilter} from 'ag-grid-react';
49-
50-
import 'ag-grid-community/styles/ag-grid.css';
51-
import 'ag-grid-community/styles/ag-theme-alpine.css';
52-
import 'ag-grid-community/styles/ag-theme-balham.css';
53-
import 'ag-grid-community/styles/ag-theme-material.css';
54-
import 'ag-grid-community/styles/ag-theme-quartz.css';
49+
import {
50+
themeAlpine,
51+
themeBalham,
52+
themeMaterial,
53+
themeQuartz,
54+
} from 'ag-grid-community';
55+
const themes = {themeAlpine, themeBalham, themeMaterial, themeQuartz};
5556

5657
// d3 imports
5758
import * as d3Format from 'd3-format';
@@ -159,6 +160,7 @@ export function DashAgGrid(props) {
159160
const parsedCondition =
160161
esprima.parse(funcString).body[0].expression;
161162
const context = {
163+
...themes,
162164
d3,
163165
dash_clientside,
164166
...customFunctions,
@@ -176,6 +178,7 @@ export function DashAgGrid(props) {
176178
const parsedCondition =
177179
esprima.parse(funcString).body[0].expression;
178180
const context = {
181+
...themes,
179182
d3,
180183
dash_clientside,
181184
...customFunctions,
@@ -195,6 +198,7 @@ export function DashAgGrid(props) {
195198
const parsedCondition =
196199
esprima.parse(funcString).body[0].expression;
197200
const context = {
201+
...themes,
198202
d3,
199203
...customFunctions,
200204
...window.dashAgGridFunctions,
@@ -1532,6 +1536,14 @@ export function DashAgGrid(props) {
15321536
omit(NO_CONVERT_PROPS, {...dashGridOptions, ...restProps})
15331537
);
15341538

1539+
if ('theme' in convertedProps) {
1540+
if (typeof convertedProps.theme === 'function') {
1541+
convertedProps.theme = convertedProps.theme();
1542+
} else if (convertedProps.theme in themes) {
1543+
convertedProps.theme = themes[convertedProps.theme];
1544+
}
1545+
}
1546+
15351547
let alignedGrids;
15361548
if (dashGridOptions) {
15371549
if ('alignedGrids' in dashGridOptions) {

0 commit comments

Comments
 (0)