99 IgrTreeGrid ,
1010 IgrColumn ,
1111} from "igniteui-react-grids" ;
12- import { EmployeesNestedTreeData } from "./EmployeesNestedTreeData" ;
12+ import { EmployeesNestedTreeData , EmployeesNestedTreeDataItem } from "./EmployeesNestedTreeData" ;
1313
1414import "igniteui-react-grids/grids/combined" ;
1515import "igniteui-react-grids/grids/themes/light/bootstrap.css" ;
@@ -21,6 +21,13 @@ export default function App() {
2121 const treeGridRef = useRef < IgrTreeGrid > ( null ) ;
2222 const treeGridRef2 = useRef < IgrTreeGrid > ( null ) ;
2323
24+ // Recursive function to add the row and its children
25+ function addRowAndChildren ( row :EmployeesNestedTreeDataItem , newData :EmployeesNestedTreeDataItem [ ] ) {
26+ newData . push ( row ) ;
27+ const children = employeesData . filter ( emp => emp . ParentID === row . ID ) ;
28+ children . forEach ( child => addRowAndChildren ( child , newData ) ) ;
29+ }
30+
2431 function RowDragEnd ( grid : IgrTreeGrid , evt : any ) {
2532 const grid2 = treeGridRef2 . current ;
2633 const ghostElement = evt . detail . dragDirective . ghostElement ;
@@ -31,8 +38,11 @@ export default function App() {
3138 const withinXBounds = dragElementPos . x >= gridPosition . x && dragElementPos . x <= gridPosition . x + gridPosition . width ;
3239 const withinYBounds = dragElementPos . y >= gridPosition . y && dragElementPos . y <= gridPosition . y + gridPosition . height ;
3340 if ( withinXBounds && withinYBounds ) {
34- console . log ( evt . detail . dragData . data . ParentID ) ;
35- treeGridRef2 . current . addRow ( evt . detail . dragData . data , null ) ;
41+
42+ const newData = [ ...grid2 . data ] ;
43+ const draggedRowData = evt . detail . dragData . data ;
44+ addRowAndChildren ( draggedRowData , newData ) ;
45+ grid2 . data = newData ;
3646 }
3747 }
3848 }
0 commit comments