@@ -46,6 +46,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
4646 IgxGridRowCustomGhostDraggableComponent ,
4747 IgxGridFeaturesRowDragComponent ,
4848 IgxHierarchicalGridTestComponent ,
49+ IgxHierarchicalGridCustomGhostTestComponent ,
4950 IgxTreeGridTestComponent
5051 ] ,
5152 imports : [
@@ -391,6 +392,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
391392 fixture . detectChanges ( ) ;
392393 dragIndicatorElements = fixture . debugElement . queryAll ( By . css ( '.' + CSS_CLASS_DRAG_INDICATOR ) ) ;
393394 dragRows = fixture . debugElement . queryAll ( By . directive ( IgxRowDragDirective ) ) ;
395+ const rowDragDirective = dragRows [ 1 ] . injector . get ( IgxRowDragDirective ) as any ;
394396 const dragIndicatorElement = dragIndicatorElements [ 2 ] . nativeElement ;
395397 const startPoint : Point = UIInteractions . getPointFromElement ( dragIndicatorElement ) ;
396398 const movePoint : Point = UIInteractions . getPointFromElement ( rows [ 4 ] . nativeElement ) ;
@@ -403,6 +405,10 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
403405 ghostElements = document . getElementsByClassName ( CSS_CLASS_GHOST_ROW ) ;
404406 expect ( ghostElements . length ) . toEqual ( 1 ) ;
405407
408+ expect ( rowDragDirective . ghostContext . data . ProductName ) . toEqual ( 'NetAdvantage' ) ;
409+ expect ( rowDragDirective . ghostContext . data . ID ) . toEqual ( 2 ) ;
410+ expect ( rowDragDirective . ghostContext . grid ) . toEqual ( grid ) ;
411+
406412 const ghostText = document . getElementsByClassName ( CSS_CLASS_GHOST_ROW ) [ 0 ] . textContent ;
407413 expect ( ghostText ) . toEqual ( ' Moving a row! ' ) ;
408414 } ) ) ;
@@ -794,7 +800,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
794800 expect ( dragCell . value ) . toEqual ( newCellValue ) ;
795801 } ) ) ;
796802 } ) ;
797- describe ( 'Hiearchical Grid Tests' , ( ) => {
803+ describe ( 'Hierarchical Grid Tests' , ( ) => {
798804 let dragGrid : IgxHierarchicalGridComponent ;
799805 let dropGrid : IgxHierarchicalGridComponent ;
800806 let dragRows : DebugElement [ ] ;
@@ -809,7 +815,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
809815 dragRows = fixture . debugElement . queryAll ( By . directive ( IgxRowDragDirective ) ) ;
810816 } ) ) ;
811817
812- it ( 'should be able to drag row on every hiearchical level' , ( async ( ) => {
818+ it ( 'should be able to drag row on every hierarchical level' , ( async ( ) => {
813819 // first level row
814820 let dragIndicatorElement : Element = dragIndicatorElements [ 1 ] . nativeElement ;
815821 let rowToDrag = dragGrid . getRowByIndex ( 0 ) ;
@@ -863,6 +869,47 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
863869 await pointerUp ( dragIndicatorElement , dropPoint , fixture ) ;
864870 verifyRowDragEndEvent ( nestedChildGrid , rowToDrag , rowDragDirective , false , 1 ) ;
865871 } ) ) ;
872+
873+ it ( 'should correctly create custom ghost element' , ( async ( ) => {
874+ fixture = TestBed . createComponent ( IgxHierarchicalGridCustomGhostTestComponent ) ;
875+ dragGrid = fixture . componentInstance . hDragGrid ;
876+ fixture . detectChanges ( ) ;
877+ dragIndicatorElements = fixture . debugElement . queryAll ( By . css ( '.' + CSS_CLASS_DRAG_INDICATOR ) ) ;
878+ dragRows = fixture . debugElement . queryAll ( By . directive ( IgxRowDragDirective ) ) ;
879+
880+ // first level row
881+ let dragIndicatorElement : Element = dragIndicatorElements [ 1 ] . nativeElement ;
882+ let rowToDrag = dragGrid . getRowByIndex ( 0 ) ;
883+ let rowDragDirective = dragRows [ 0 ] . injector . get ( IgxRowDragDirective ) as any ;
884+
885+ let startPoint : Point = UIInteractions . getPointFromElement ( dragIndicatorElement ) ;
886+ const movePoint : Point = UIInteractions . getPointFromElement ( dragGrid . getRowByIndex ( 3 ) . nativeElement ) ;
887+ const dropPoint : Point = UIInteractions . getPointFromElement ( dropAreaElement ) ;
888+
889+ await pointerDown ( dragIndicatorElement , startPoint , fixture ) ;
890+ await pointerMove ( dragIndicatorElement , movePoint , fixture ) ;
891+ await pointerMove ( dragIndicatorElement , dropPoint , fixture ) ;
892+ await pointerUp ( dragIndicatorElement , dropPoint , fixture ) ;
893+
894+ expect ( rowDragDirective . ghostContext . data . ProductName ) . toEqual ( 'Product: A0' ) ;
895+ expect ( rowDragDirective . ghostContext . grid ) . toEqual ( dragGrid ) ;
896+
897+ // second level row
898+ dragIndicatorElement = dragIndicatorElements [ 8 ] . nativeElement ;
899+ const childGrid = dragGrid . hgridAPI . getChildGrids ( false ) [ 0 ] ;
900+ rowToDrag = childGrid . getRowByIndex ( 0 ) ;
901+ rowDragDirective = dragRows [ 4 ] . injector . get ( IgxRowDragDirective ) ;
902+ startPoint = UIInteractions . getPointFromElement ( dragIndicatorElement ) ;
903+
904+ await pointerDown ( dragIndicatorElement , startPoint , fixture ) ;
905+ await pointerMove ( dragIndicatorElement , movePoint , fixture ) ;
906+ await pointerMove ( dragIndicatorElement , dropPoint , fixture ) ;
907+ await pointerUp ( dragIndicatorElement , dropPoint , fixture ) ;
908+
909+ expect ( rowDragDirective . ghostContext . data . ProductName ) . toEqual ( 'Product: A0' ) ;
910+ expect ( rowDragDirective . ghostContext . data . ChildLevels ) . toEqual ( 2 ) ;
911+ expect ( rowDragDirective . ghostContext . grid ) . toEqual ( childGrid ) ;
912+ } ) ) ;
866913 } ) ;
867914 describe ( 'Tree Grid Tests' , ( ) => {
868915 let dragGrid : IgxTreeGridComponent ;
@@ -1137,6 +1184,57 @@ export class IgxHierarchicalGridTestComponent {
11371184 }
11381185}
11391186
1187+ @Component ( {
1188+ template : `
1189+ <igx-hierarchical-grid #hierarchicalDragGrid [data]="data"
1190+ [autoGenerate]="true" [height]="'500px'" [width]="'1500px'"
1191+ primaryKey="ID" [expandChildren]='true' [rowDraggable]="true">
1192+ <igx-row-island [key]="'childData'" [expandChildren]='true' [autoGenerate]="true" [rowDraggable]="true" #rowIsland>
1193+ <igx-row-island [key]="'childData2'" [autoGenerate]="true" [rowDraggable]="true" #rowIsland2 >
1194+ </igx-row-island>
1195+ <ng-template let-data igxRowDragGhost>
1196+ <div>
1197+ Moving {{data.ProductName}}!
1198+ </div>
1199+ </ng-template>
1200+ </igx-row-island>
1201+ <ng-template let-data igxRowDragGhost>
1202+ <div>
1203+ Moving {{data.ProductName}}!
1204+ </div>
1205+ </ng-template>
1206+ </igx-hierarchical-grid>`
1207+ } )
1208+ export class IgxHierarchicalGridCustomGhostTestComponent {
1209+ public data ;
1210+ newData = [ ] ;
1211+ @ViewChild ( 'hierarchicalDragGrid' , { read : IgxHierarchicalGridComponent , static : true } ) public hDragGrid : IgxHierarchicalGridComponent ;
1212+ @ViewChild ( 'rowIsland' , { read : IgxRowIslandComponent , static : true } ) public rowIsland : IgxRowIslandComponent ;
1213+ @ViewChild ( 'rowIsland2' , { read : IgxRowIslandComponent , static : true } ) public rowIsland2 : IgxRowIslandComponent ;
1214+
1215+ constructor ( ) {
1216+ this . data = this . generateData ( 2 , 3 ) ;
1217+ }
1218+ generateData ( count : number , level : number ) {
1219+ const prods = [ ] ;
1220+ const currLevel = level ;
1221+ let children ;
1222+ for ( let i = 0 ; i < count ; i ++ ) {
1223+ const item = {
1224+ ID : i , ChildLevels : currLevel , ProductName : 'Product: A' + i , 'Col1' : i ,
1225+ 'Col2' : i , 'Col3' : i
1226+ } ;
1227+ if ( currLevel > 1 ) {
1228+ children = this . generateData ( count / 2 , currLevel - 1 ) ;
1229+ const childProp = currLevel === 3 ? 'childData' : 'childData2' ;
1230+ item [ childProp ] = children ;
1231+ }
1232+ prods . push ( item ) ;
1233+ }
1234+ return prods ;
1235+ }
1236+ }
1237+
11401238@Component ( {
11411239 template : `
11421240 <igx-tree-grid #treeGrid [data]="data" primaryKey="employeeID" foreignKey="PID" width="900px" height="500px" [rowDraggable]="true">
0 commit comments