Skip to content

Commit 09875b3

Browse files
authored
Update row-drag-base samples for React 19 (#792)
1 parent aa381ad commit 09875b3

File tree

3 files changed

+183
-200
lines changed

3 files changed

+183
-200
lines changed

samples/grids/grid/row-drag-base/src/index.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,34 @@ import React, { useRef } from 'react';
22
import ReactDOM from 'react-dom/client';
33
import './index.css';
44

5-
import { IgrGridModule, IgrRowDragEndEventArgs } from 'igniteui-react-grids';
5+
import { IgrRowDragEndEventArgs } from 'igniteui-react-grids';
66
import { IgrGrid, IgrColumn } from 'igniteui-react-grids';
77
import { CustomersData } from './CustomersData';
88

99
import 'igniteui-react-grids/grids/themes/light/bootstrap.css';
1010

11-
const mods: any[] = [
12-
IgrGridModule
13-
];
14-
mods.forEach((m) => m.register());
15-
1611
export default function App() {
1712
const data = new CustomersData();
1813
const rightGridRef = useRef<IgrGrid>(null);
1914

20-
function onGridRowDragEnd(evt: IgrRowDragEndEventArgs): void {
21-
const grid = evt.target as IgrGrid;
15+
const onGridRowDragEnd = (evt: IgrRowDragEndEventArgs) => {
16+
const leftGrid = evt.target as IgrGrid;
2217
const ghostElement = evt.detail.dragDirective.ghostElement;
2318
if (ghostElement != null) {
2419
const dragElementPos = ghostElement.getBoundingClientRect();
25-
const gridPosition = document.getElementById("rightGrid").getElementsByTagName("igc-grid")[0].getBoundingClientRect();
26-
20+
const gridPosition = document.getElementById("rightGrid").getBoundingClientRect();
21+
2722
const withinXBounds = dragElementPos.x >= gridPosition.x && dragElementPos.x <= gridPosition.x + gridPosition.width;
2823
const withinYBounds = dragElementPos.y >= gridPosition.y && dragElementPos.y <= gridPosition.y + gridPosition.height;
2924
if (withinXBounds && withinYBounds) {
30-
grid.deleteRow(evt.detail.dragData.key);
25+
leftGrid.deleteRow(evt.detail.dragData.key);
3126
rightGridRef.current.addRow(evt.detail.dragData.data);
3227
}
3328
}
3429
}
3530

3631
return (
37-
<div className="container sample">
32+
<div className="container sample">
3833
<div className="container horizontal wrapper">
3934
<IgrGrid data={data} width="40%" primaryKey='ID' autoGenerate={false} rowDraggable={true} onRowDragEnd={onGridRowDragEnd}>
4035
<IgrColumn field="ID" width="100px"></IgrColumn>
@@ -64,9 +59,9 @@ export default function App() {
6459
</IgrGrid>
6560
</div>
6661
</div>
67-
);
62+
);
6863
}
6964

7065
// rendering above component in the React DOM
7166
const root = ReactDOM.createRoot(document.getElementById('root'));
72-
root.render(<App/>);
67+
root.render(<App />);

0 commit comments

Comments
 (0)