@linzjs/step-ag-grid 17.4.1 → 17.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/GridTheme.scss +1 -5
- package/dist/src/components/Grid.d.ts +1 -1
- package/dist/step-ag-grid.cjs.js +30 -9
- package/dist/step-ag-grid.cjs.js.map +1 -1
- package/dist/step-ag-grid.esm.js +30 -9
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +45 -13
- package/src/stories/grid/GridDragRow.stories.tsx +2 -1
- package/src/styles/GridTheme.scss +1 -5
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CellClickedEvent,
|
|
3
|
+
ColDef,
|
|
4
|
+
ColGroupDef,
|
|
5
|
+
ColumnResizedEvent,
|
|
6
|
+
IClientSideRowModel,
|
|
7
|
+
ModelUpdatedEvent,
|
|
8
|
+
RowHighlightPosition,
|
|
9
|
+
RowNode,
|
|
10
|
+
} from "ag-grid-community";
|
|
2
11
|
import { CellClassParams, EditableCallback, EditableCallbackParams } from "ag-grid-community/dist/lib/entities/colDef";
|
|
3
12
|
import { GridOptions } from "ag-grid-community/dist/lib/entities/gridOptions";
|
|
4
13
|
import {
|
|
@@ -7,6 +16,7 @@ import {
|
|
|
7
16
|
CellKeyDownEvent,
|
|
8
17
|
GridReadyEvent,
|
|
9
18
|
RowDragEndEvent,
|
|
19
|
+
RowDragMoveEvent,
|
|
10
20
|
SelectionChangedEvent,
|
|
11
21
|
} from "ag-grid-community/dist/lib/events";
|
|
12
22
|
import { AgGridReact } from "ag-grid-react";
|
|
@@ -50,7 +60,7 @@ export interface GridProps {
|
|
|
50
60
|
autoSelectFirstRow?: boolean;
|
|
51
61
|
onColumnMoved?: GridOptions["onColumnMoved"];
|
|
52
62
|
rowDragText?: GridOptions["rowDragText"];
|
|
53
|
-
onRowDragEnd?: (movedRow: any, targetRow: any, targetIndex: number) => void
|
|
63
|
+
onRowDragEnd?: (movedRow: any, targetRow: any, targetIndex: number) => Promise<void>;
|
|
54
64
|
alwaysShowVerticalScroll?: boolean;
|
|
55
65
|
suppressColumnVirtualization?: GridOptions["suppressColumnVirtualisation"];
|
|
56
66
|
/**
|
|
@@ -339,7 +349,6 @@ export const Grid = ({
|
|
|
339
349
|
},
|
|
340
350
|
checkboxSelection: params.selectable,
|
|
341
351
|
headerComponent: rowSelection === "multiple" ? GridHeaderSelect : null,
|
|
342
|
-
//headerCheckboxSelection:true,
|
|
343
352
|
suppressHeaderKeyboardEvent: (e) => {
|
|
344
353
|
if (!params.selectable) return false;
|
|
345
354
|
if ((e.event.key === "Enter" || e.event.key === " ") && !e.event.repeat) {
|
|
@@ -590,15 +599,38 @@ export const Grid = ({
|
|
|
590
599
|
|
|
591
600
|
const gridContextMenu = useGridContextMenu({ contextMenu: params.contextMenu, contextMenuSelectRow });
|
|
592
601
|
|
|
602
|
+
const onRowDragLeave = useCallback((event: RowDragMoveEvent) => {
|
|
603
|
+
const clientSideRowModel = event.api.getModel() as IClientSideRowModel;
|
|
604
|
+
clientSideRowModel.highlightRowAtPixel(null);
|
|
605
|
+
}, []);
|
|
606
|
+
|
|
607
|
+
const onRowDragMove = useCallback((event: RowDragMoveEvent) => {
|
|
608
|
+
const clientSideRowModel = event.api.getModel() as IClientSideRowModel;
|
|
609
|
+
clientSideRowModel.highlightRowAtPixel(event.node as RowNode<any>, event.y);
|
|
610
|
+
}, []);
|
|
611
|
+
|
|
593
612
|
const onRowDragEnd = useCallback(
|
|
594
|
-
(event: RowDragEndEvent) => {
|
|
595
|
-
const
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
613
|
+
async (event: RowDragEndEvent) => {
|
|
614
|
+
const clientSideRowModel = event.api.getModel() as IClientSideRowModel;
|
|
615
|
+
if (event.node.rowIndex) {
|
|
616
|
+
const lastHighlightedRowNode = clientSideRowModel.getLastHighlightedRowNode();
|
|
617
|
+
const isBelow = lastHighlightedRowNode && lastHighlightedRowNode.highlighted === RowHighlightPosition.Below;
|
|
618
|
+
|
|
619
|
+
let targetIndex = event.overIndex;
|
|
620
|
+
if (event.node.rowIndex > event.overIndex) {
|
|
621
|
+
targetIndex += isBelow ? 1 : 0;
|
|
622
|
+
} else {
|
|
623
|
+
targetIndex += isBelow ? 0 : -1;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
const moved = event.node.data;
|
|
627
|
+
const target = event.overNode?.data;
|
|
628
|
+
moved.id != target.id && //moved over a different row
|
|
629
|
+
moved.rowIndex != targetIndex && //moved to a different index
|
|
630
|
+
params.onRowDragEnd &&
|
|
631
|
+
(await params.onRowDragEnd(moved, target, targetIndex));
|
|
632
|
+
}
|
|
633
|
+
clientSideRowModel.highlightRowAtPixel(null);
|
|
602
634
|
},
|
|
603
635
|
[params],
|
|
604
636
|
);
|
|
@@ -666,9 +698,9 @@ export const Grid = ({
|
|
|
666
698
|
preventDefaultOnContextMenu={true}
|
|
667
699
|
onCellContextMenu={gridContextMenu.cellContextMenu}
|
|
668
700
|
rowDragText={params.rowDragText}
|
|
669
|
-
|
|
670
|
-
suppressMoveWhenRowDragging={true}
|
|
701
|
+
onRowDragMove={onRowDragMove}
|
|
671
702
|
onRowDragEnd={onRowDragEnd}
|
|
703
|
+
onRowDragLeave={onRowDragLeave}
|
|
672
704
|
/>
|
|
673
705
|
</div>
|
|
674
706
|
</div>
|
|
@@ -95,6 +95,7 @@ const GridDragRowTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
|
|
|
95
95
|
{ id: 1000, position: "Tester", age: 30, height: `6'4"`, desc: "Tests application", dd: "1" },
|
|
96
96
|
{ id: 1001, position: "Developer", age: 12, height: `5'3"`, desc: "Develops application", dd: "2" },
|
|
97
97
|
{ id: 1002, position: "Manager", age: 65, height: `5'9"`, desc: "Manages", dd: "3" },
|
|
98
|
+
{ id: 1003, position: "BA", age: 42, height: `5'7"`, desc: "BAs", dd: "4" },
|
|
98
99
|
]);
|
|
99
100
|
|
|
100
101
|
return (
|
|
@@ -109,7 +110,7 @@ const GridDragRowTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
|
|
|
109
110
|
defaultColDef={{ sortable: false }}
|
|
110
111
|
rowData={rowData}
|
|
111
112
|
onRowDragEnd={(row, _, targetIndex) => {
|
|
112
|
-
alert(`Row ${row.id}
|
|
113
|
+
alert(`Row ${row.id} request to be moved to index ${targetIndex}.`);
|
|
113
114
|
}}
|
|
114
115
|
rowDragText={(params) => `${params.rowNode?.data.id} - ${params.rowNode?.data.position}`}
|
|
115
116
|
/>
|
|
@@ -50,11 +50,6 @@ $grid-base-font-size: calc(#{lui.$base-font-size} - 1px);
|
|
|
50
50
|
|
|
51
51
|
.ag-cell[col-id="selection"] {
|
|
52
52
|
display: flex;// Fix that when you click below checkbox it doesn't process a click
|
|
53
|
-
justify-content: end; // fix alignment of cell content when grabber is present
|
|
54
|
-
|
|
55
|
-
.ag-selection-checkbox {
|
|
56
|
-
margin-right:0;
|
|
57
|
-
}
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
// fix alignment of cell content when grabber is present
|
|
@@ -92,6 +87,7 @@ $grid-base-font-size: calc(#{lui.$base-font-size} - 1px);
|
|
|
92
87
|
|
|
93
88
|
.ag-header .ag-header-cell[aria-colindex="1"] {
|
|
94
89
|
padding-left: 17px;
|
|
90
|
+
padding-right: 15px;
|
|
95
91
|
}
|
|
96
92
|
|
|
97
93
|
.ag-cell[role="gridcell"] {
|