1- /* eslint-disable simple-import-sort/imports */
2- import '@ag-grid-community/styles/ag-grid.css' ;
3- import '@ag-grid-community/styles/ag-theme-balham.css' ;
4- /* eslint-enable simple-import-sort/imports */
5-
61import MapUtil from '@terrestris/ol-util/dist/MapUtil/MapUtil' ;
72import useMap from '@terrestris/react-util/dist/Hooks/useMap/useMap' ;
83import useOlLayer from '@terrestris/react-util/dist/Hooks/useOlLayer/useOlLayer' ;
9-
10- import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model' ;
114import {
5+ AllCommunityModule ,
126 CellMouseOutEvent ,
137 CellMouseOverEvent ,
148 ColDef ,
@@ -21,28 +15,25 @@ import {
2115 RowClickedEvent ,
2216 RowNode ,
2317 RowStyle ,
24- SelectionChangedEvent
25- } from '@ag-grid-community/core' ;
18+ SelectionChangedEvent ,
19+ Theme ,
20+ themeBalham } from 'ag-grid-community' ;
2621import {
2722 AgGridReact ,
2823 AgGridReactProps
29- } from '@ag-grid-community/react' ;
30-
24+ } from 'ag-grid-react' ;
3125import _differenceWith from 'lodash/differenceWith' ;
32- import _has from 'lodash/has' ;
3326import _isFunction from 'lodash/isFunction' ;
3427import _isNil from 'lodash/isNil' ;
3528import _isNumber from 'lodash/isNumber' ;
3629import _isString from 'lodash/isString' ;
37-
3830import { getUid } from 'ol' ;
3931import OlFeature from 'ol/Feature' ;
4032import OlGeometry from 'ol/geom/Geometry' ;
4133import OlLayerBase from 'ol/layer/Base' ;
4234import OlLayerVector from 'ol/layer/Vector' ;
4335import OlMapBrowserEvent from 'ol/MapBrowserEvent' ;
4436import OlSourceVector from 'ol/source/Vector' ;
45-
4637import React , { Key , ReactElement , useCallback , useEffect , useMemo , useState } from 'react' ;
4738
4839import { CSS_PREFIX } from '../../constants' ;
@@ -65,11 +56,11 @@ interface OwnProps<T> {
6556 */
6657 height ?: number | string ;
6758 /**
68- * The theme to use for the grid. See
69- * https://www.ag-grid.com/javascript-grid-styling/ for available options .
70- * Note: CSS must be loaded to use the theme!
59+ * The theme to use for the grid. See https://www.ag-grid.com/angular-data-grid/theming/ for available options
60+ * and customization possibilities. Default is the balham theme .
61+ * NOTE: AG-Grid CSS should *not* be imported.
7162 */
72- theme ?: string ;
63+ theme ?: Theme ;
7364 /**
7465 * Custom column definitions to apply to the given column (mapping via key).
7566 */
@@ -117,7 +108,7 @@ const defaultClassName = `${CSS_PREFIX}ag-feature-grid`;
117108export type AgFeatureGridProps < T > = OwnProps < T > & RgCommonGridProps < T > & Omit < AgGridReactProps , 'theme' > ;
118109
119110ModuleRegistry . registerModules ( [
120- ClientSideRowModelModule
111+ AllCommunityModule
121112] ) ;
122113
123114/**
@@ -143,7 +134,7 @@ export function AgFeatureGrid<T>({
143134 rowStyleFn,
144135 selectStyle = defaultSelectStyle ,
145136 selectable = false ,
146- theme = 'ag-theme-balham' ,
137+ theme = themeBalham ,
147138 width,
148139 zoomToExtent = false ,
149140 ...agGridPassThroughProps
@@ -169,17 +160,6 @@ export function AgFeatureGrid<T>({
169160 style : featureStyle
170161 } ) , [ features , layerName ] , true ) ;
171162
172- const checkBoxColumnDefinition : ColDef < WithKey < T > > = useMemo ( ( ) => ( {
173- checkboxSelection : true ,
174- headerCheckboxSelection : true ,
175- headerName : '' ,
176- lockPosition : true ,
177- pinned : 'left' ,
178- suppressHeaderMenuButton : true ,
179- suppressMovable : true ,
180- width : 40
181- } ) , [ ] ) ;
182-
183163 /**
184164 * Returns the currently selected row keys.
185165 *
@@ -190,8 +170,7 @@ export function AgFeatureGrid<T>({
190170 return [ ] ;
191171 }
192172
193- const sr = gridApi . getSelectedRows ( ) ;
194- return sr . map ( row => row . key ) ;
173+ return gridApi . getSelectedRows ( ) ?. map ( row => row . key ) ?? [ ] ;
195174 } , [ gridApi ] ) ;
196175
197176 /**
@@ -326,11 +305,6 @@ export function AgFeatureGrid<T>({
326305 const feature = features [ 0 ] ;
327306 const props = feature . getProperties ( ) ;
328307
329- if ( selectable ) {
330- // adds select checkbox column
331- columns . push ( checkBoxColumnDefinition ) ;
332- }
333-
334308 const colDefsFromFeature = Object . keys ( props ) . map ( ( key : string ) : ColDef < WithKey < T > > | undefined => {
335309 if ( attributeBlacklist . includes ( key ) ) {
336310 return ;
@@ -363,7 +337,7 @@ export function AgFeatureGrid<T>({
363337 ...columns ,
364338 ...( colDefsFromFeature . filter ( c => ! _isNil ( c ) ) as ColDef < WithKey < T > > [ ] )
365339 ] ;
366- } , [ attributeBlacklist , features , selectable , checkBoxColumnDefinition ] ) ;
340+ } , [ attributeBlacklist , features ] ) ;
367341
368342 /**
369343 * Returns the table row data from all the given features.
@@ -585,28 +559,12 @@ export function AgFeatureGrid<T>({
585559
586560 const colDefs = useMemo ( ( ) => {
587561 if ( ! _isNil ( columnDefs ) ) {
588- if ( ! selectable ) {
589- return columnDefs ;
590- }
591- // check for checkbox column - if not present => add
592- const checkboxSelectionPresent = columnDefs ?.
593- some ( ( colDef : ColDef < WithKey < T > > ) =>
594- _has ( colDef , 'checkboxSelection' ) && ! _isNil ( colDef . checkboxSelection )
595- ) ;
596- if ( checkboxSelectionPresent ) {
597- return columnDefs ;
598- }
599- return [
600- checkBoxColumnDefinition ,
601- ...columnDefs
602- ] ;
562+ return columnDefs ;
603563 }
604564 return getColumnDefsFromFeature ( ) ;
605565 } , [
606- checkBoxColumnDefinition ,
607566 columnDefs ,
608- getColumnDefsFromFeature ,
609- selectable
567+ getColumnDefsFromFeature
610568 ] ) ;
611569
612570 const passedRowData = useMemo ( ( ) => ! _isNil ( rowData ) ? rowData : getRowData ( ) , [
@@ -615,8 +573,8 @@ export function AgFeatureGrid<T>({
615573 ] ) ;
616574
617575 const finalClassName = className
618- ? `${ className } ${ defaultClassName } ${ theme } `
619- : `${ defaultClassName } ${ theme } ` ;
576+ ? `${ className } ${ defaultClassName } `
577+ : `${ defaultClassName } ` ;
620578
621579 return (
622580 < div
@@ -632,8 +590,11 @@ export function AgFeatureGrid<T>({
632590 onRowClicked = { onRowClickInner }
633591 onSelectionChanged = { onSelectionChanged }
634592 rowData = { passedRowData }
635- rowSelection = "multiple"
636- suppressRowClickSelection
593+ rowSelection = { selectable ? {
594+ mode : 'multiRow' ,
595+ enableClickSelection : false
596+ } : undefined }
597+ theme = { theme }
637598 { ...agGridPassThroughProps }
638599 />
639600 </ div >
0 commit comments