@@ -44,8 +44,10 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
44
44
TestBed . configureTestingModule ( {
45
45
declarations : [
46
46
IgxGridRowDraggableComponent ,
47
+ IgxGridRowCustomGhostDraggableComponent ,
47
48
IgxGridFeaturesRowDragComponent ,
48
49
IgxHierarchicalGridTestComponent ,
50
+ IgxHierarchicalGridCustomGhostTestComponent ,
49
51
IgxTreeGridTestComponent
50
52
] ,
51
53
imports : [
@@ -384,6 +386,33 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
384
386
const ghostElements = document . getElementsByClassName ( CSS_CLASS_GHOST_ROW ) ;
385
387
expect ( ghostElements . length ) . toEqual ( 0 ) ;
386
388
} ) ) ;
389
+
390
+ it ( 'should correctly create custom ghost element' , ( async ( ) => {
391
+ fixture = TestBed . createComponent ( IgxGridRowCustomGhostDraggableComponent ) ;
392
+ grid = fixture . componentInstance . instance ;
393
+ fixture . detectChanges ( ) ;
394
+ dragIndicatorElements = fixture . debugElement . queryAll ( By . css ( '.' + CSS_CLASS_DRAG_INDICATOR ) ) ;
395
+ dragRows = fixture . debugElement . queryAll ( By . directive ( IgxRowDragDirective ) ) ;
396
+ const rowDragDirective = dragRows [ 1 ] . injector . get ( IgxRowDragDirective ) as any ;
397
+ const dragIndicatorElement = dragIndicatorElements [ 2 ] . nativeElement ;
398
+ const startPoint : Point = UIInteractions . getPointFromElement ( dragIndicatorElement ) ;
399
+ const movePoint : Point = UIInteractions . getPointFromElement ( rows [ 4 ] . nativeElement ) ;
400
+ const dropPoint : Point = UIInteractions . getPointFromElement ( dropAreaElement ) ;
401
+ let ghostElements : HTMLCollection ;
402
+
403
+ await pointerDown ( dragIndicatorElement , startPoint , fixture ) ;
404
+ await pointerMove ( dragIndicatorElement , movePoint , fixture ) ;
405
+ await pointerMove ( dragIndicatorElement , dropPoint , fixture ) ;
406
+ ghostElements = document . getElementsByClassName ( CSS_CLASS_GHOST_ROW ) ;
407
+ expect ( ghostElements . length ) . toEqual ( 1 ) ;
408
+
409
+ expect ( rowDragDirective . ghostContext . data . ProductName ) . toEqual ( 'NetAdvantage' ) ;
410
+ expect ( rowDragDirective . ghostContext . data . ID ) . toEqual ( 2 ) ;
411
+ expect ( rowDragDirective . ghostContext . grid ) . toEqual ( grid ) ;
412
+
413
+ const ghostText = document . getElementsByClassName ( CSS_CLASS_GHOST_ROW ) [ 0 ] . textContent ;
414
+ expect ( ghostText ) . toEqual ( ' Moving a row! ' ) ;
415
+ } ) ) ;
387
416
} ) ;
388
417
describe ( 'Grid Features Integration Tests' , ( ) => {
389
418
let dragGrid : IgxGridComponent ;
@@ -635,8 +664,8 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
635
664
expect ( row . grid . rowDragging ) . toBeTruthy ( ) ;
636
665
637
666
const ghostElements = document . getElementsByClassName ( CSS_CLASS_GHOST_ROW ) ;
638
- const ghostElement = ghostElements [ 0 ] ;
639
- expect ( ghostElements . length ) . toEqual ( 1 ) ;
667
+ const ghostElement = ghostElements [ 1 ] ;
668
+ expect ( ghostElements . length ) . toEqual ( 2 ) ;
640
669
expect ( ghostElement . classList . contains ( CSS_CLASS_SELECTED_ROW ) ) . toBeFalsy ( ) ;
641
670
642
671
await pointerMove ( dragIndicatorElement , dropPoint , fixture ) ;
@@ -787,7 +816,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
787
816
dragRows = fixture . debugElement . queryAll ( By . directive ( IgxRowDragDirective ) ) ;
788
817
} ) ) ;
789
818
790
- it ( 'should be able to drag row on every hiearchical level' , ( async ( ) => {
819
+ it ( 'should be able to drag row on every hierarchical level' , ( async ( ) => {
791
820
// first level row
792
821
let dragIndicatorElement : Element = dragIndicatorElements [ 1 ] . nativeElement ;
793
822
let rowToDrag = dragGrid . getRowByIndex ( 0 ) ;
@@ -841,6 +870,47 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
841
870
await pointerUp ( dragIndicatorElement , dropPoint , fixture ) ;
842
871
verifyRowDragEndEvent ( nestedChildGrid , rowToDrag , rowDragDirective , false , 1 ) ;
843
872
} ) ) ;
873
+
874
+ it ( 'should correctly create custom ghost element' , ( async ( ) => {
875
+ fixture = TestBed . createComponent ( IgxHierarchicalGridCustomGhostTestComponent ) ;
876
+ dragGrid = fixture . componentInstance . hDragGrid ;
877
+ fixture . detectChanges ( ) ;
878
+ dragIndicatorElements = fixture . debugElement . queryAll ( By . css ( '.' + CSS_CLASS_DRAG_INDICATOR ) ) ;
879
+ dragRows = fixture . debugElement . queryAll ( By . directive ( IgxRowDragDirective ) ) ;
880
+
881
+ // first level row
882
+ let dragIndicatorElement : Element = dragIndicatorElements [ 1 ] . nativeElement ;
883
+ let rowToDrag = dragGrid . getRowByIndex ( 0 ) ;
884
+ let rowDragDirective = dragRows [ 0 ] . injector . get ( IgxRowDragDirective ) as any ;
885
+
886
+ let startPoint : Point = UIInteractions . getPointFromElement ( dragIndicatorElement ) ;
887
+ const movePoint : Point = UIInteractions . getPointFromElement ( dragGrid . getRowByIndex ( 3 ) . nativeElement ) ;
888
+ const dropPoint : Point = UIInteractions . getPointFromElement ( dropAreaElement ) ;
889
+
890
+ await pointerDown ( dragIndicatorElement , startPoint , fixture ) ;
891
+ await pointerMove ( dragIndicatorElement , movePoint , fixture ) ;
892
+ await pointerMove ( dragIndicatorElement , dropPoint , fixture ) ;
893
+ await pointerUp ( dragIndicatorElement , dropPoint , fixture ) ;
894
+
895
+ expect ( rowDragDirective . ghostContext . data . ProductName ) . toEqual ( 'Product: A0' ) ;
896
+ expect ( rowDragDirective . ghostContext . grid ) . toEqual ( dragGrid ) ;
897
+
898
+ // second level row
899
+ dragIndicatorElement = dragIndicatorElements [ 8 ] . nativeElement ;
900
+ const childGrid = dragGrid . hgridAPI . getChildGrids ( false ) [ 0 ] ;
901
+ rowToDrag = childGrid . getRowByIndex ( 0 ) ;
902
+ rowDragDirective = dragRows [ 4 ] . injector . get ( IgxRowDragDirective ) ;
903
+ startPoint = UIInteractions . getPointFromElement ( dragIndicatorElement ) ;
904
+
905
+ await pointerDown ( dragIndicatorElement , startPoint , fixture ) ;
906
+ await pointerMove ( dragIndicatorElement , movePoint , fixture ) ;
907
+ await pointerMove ( dragIndicatorElement , dropPoint , fixture ) ;
908
+ await pointerUp ( dragIndicatorElement , dropPoint , fixture ) ;
909
+
910
+ expect ( rowDragDirective . ghostContext . data . ProductName ) . toEqual ( 'Product: A0' ) ;
911
+ expect ( rowDragDirective . ghostContext . data . ChildLevels ) . toEqual ( 2 ) ;
912
+ expect ( rowDragDirective . ghostContext . grid ) . toEqual ( childGrid ) ;
913
+ } ) ) ;
844
914
} ) ;
845
915
describe ( 'Tree Grid Tests' , ( ) => {
846
916
let dragGrid : IgxTreeGridComponent ;
@@ -857,7 +927,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
857
927
dragRows = fixture . debugElement . queryAll ( By . directive ( IgxRowDragDirective ) ) ;
858
928
} ) ) ;
859
929
860
- it ( 'should be able to drag row on every hiearchical level' , ( async ( ) => {
930
+ it ( 'should be able to drag row on every hierarchical level' , ( async ( ) => {
861
931
// first level row
862
932
let dragIndicatorElement : Element = dragIndicatorElements [ 1 ] . nativeElement ;
863
933
let rowToDrag = dragGrid . getRowByIndex ( 0 ) ;
@@ -960,6 +1030,65 @@ export class IgxGridRowDraggableComponent extends DataParent {
960
1030
}
961
1031
}
962
1032
1033
+ @Component ( {
1034
+ template : `
1035
+ <igx-grid #grid
1036
+ [width]='width'
1037
+ [height]='height'
1038
+ primaryKey="ID"
1039
+ [data]="data"
1040
+ [autoGenerate]="true" (onColumnInit)="columnsCreated($event)" (onGroupingDone)="onGroupingDoneHandler($event)"
1041
+ [rowEditable]="true" [rowDraggable]="enableRowDraggable"
1042
+ >
1043
+ <ng-template let-data igxRowDragGhost>
1044
+ <div class="dragGhost">
1045
+ <igx-icon fontSet="material"></igx-icon>
1046
+ Moving a row!
1047
+ </div>
1048
+ </ng-template>
1049
+ </igx-grid>
1050
+ <div #dropArea class="droppable-area" igxDrop (dropped)="onRowDrop($event)"
1051
+ [ngStyle]="{width:'100px', height:'100px', backgroundColor:'red'}">
1052
+ </div>
1053
+ <div #nonDroppableArea class="non-droppable-area"
1054
+ [ngStyle]="{width:'100px', height:'100px', backgroundColor:'yellow'}">
1055
+ </div>
1056
+ `
1057
+ } )
1058
+ export class IgxGridRowCustomGhostDraggableComponent extends DataParent {
1059
+ public width = '800px' ;
1060
+ public height = null ;
1061
+
1062
+ @ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
1063
+ public instance : IgxGridComponent ;
1064
+
1065
+ @ViewChild ( 'dropArea' , { read : IgxDropDirective , static : true } )
1066
+ public dropArea : IgxDropDirective ;
1067
+
1068
+ public enableSorting = false ;
1069
+ public enableFiltering = false ;
1070
+ public enableResizing = false ;
1071
+ public enableEditing = true ;
1072
+ public enableGrouping = true ;
1073
+ public enableRowEditing = true ;
1074
+ public enableRowDraggable = true ;
1075
+ public currentSortExpressions ;
1076
+
1077
+ public columnsCreated ( column : IgxColumnComponent ) {
1078
+ column . sortable = this . enableSorting ;
1079
+ column . filterable = this . enableFiltering ;
1080
+ column . resizable = this . enableResizing ;
1081
+ column . editable = this . enableEditing ;
1082
+ column . groupable = this . enableGrouping ;
1083
+ }
1084
+ public onGroupingDoneHandler ( sortExpr ) {
1085
+ this . currentSortExpressions = sortExpr ;
1086
+ }
1087
+ public onRowDrop ( args ) {
1088
+ args . cancel = true ;
1089
+ }
1090
+ }
1091
+
963
1092
@Component ( {
964
1093
template : `
965
1094
<igx-grid #dragGrid
@@ -1056,6 +1185,57 @@ export class IgxHierarchicalGridTestComponent {
1056
1185
}
1057
1186
}
1058
1187
1188
+ @Component ( {
1189
+ template : `
1190
+ <igx-hierarchical-grid #hierarchicalDragGrid [data]="data"
1191
+ [autoGenerate]="true" [height]="'500px'" [width]="'1500px'"
1192
+ primaryKey="ID" [expandChildren]='true' [rowDraggable]="true">
1193
+ <igx-row-island [key]="'childData'" [expandChildren]='true' [autoGenerate]="true" [rowDraggable]="true" #rowIsland>
1194
+ <igx-row-island [key]="'childData2'" [autoGenerate]="true" [rowDraggable]="true" #rowIsland2 >
1195
+ </igx-row-island>
1196
+ <ng-template let-data igxRowDragGhost>
1197
+ <div>
1198
+ Moving {{data.ProductName}}!
1199
+ </div>
1200
+ </ng-template>
1201
+ </igx-row-island>
1202
+ <ng-template let-data igxRowDragGhost>
1203
+ <div>
1204
+ Moving {{data.ProductName}}!
1205
+ </div>
1206
+ </ng-template>
1207
+ </igx-hierarchical-grid>`
1208
+ } )
1209
+ export class IgxHierarchicalGridCustomGhostTestComponent {
1210
+ public data ;
1211
+ newData = [ ] ;
1212
+ @ViewChild ( 'hierarchicalDragGrid' , { read : IgxHierarchicalGridComponent , static : true } ) public hDragGrid : IgxHierarchicalGridComponent ;
1213
+ @ViewChild ( 'rowIsland' , { read : IgxRowIslandComponent , static : true } ) public rowIsland : IgxRowIslandComponent ;
1214
+ @ViewChild ( 'rowIsland2' , { read : IgxRowIslandComponent , static : true } ) public rowIsland2 : IgxRowIslandComponent ;
1215
+
1216
+ constructor ( ) {
1217
+ this . data = this . generateData ( 2 , 3 ) ;
1218
+ }
1219
+ generateData ( count : number , level : number ) {
1220
+ const prods = [ ] ;
1221
+ const currLevel = level ;
1222
+ let children ;
1223
+ for ( let i = 0 ; i < count ; i ++ ) {
1224
+ const item = {
1225
+ ID : i , ChildLevels : currLevel , ProductName : 'Product: A' + i , 'Col1' : i ,
1226
+ 'Col2' : i , 'Col3' : i
1227
+ } ;
1228
+ if ( currLevel > 1 ) {
1229
+ children = this . generateData ( count / 2 , currLevel - 1 ) ;
1230
+ const childProp = currLevel === 3 ? 'childData' : 'childData2' ;
1231
+ item [ childProp ] = children ;
1232
+ }
1233
+ prods . push ( item ) ;
1234
+ }
1235
+ return prods ;
1236
+ }
1237
+ }
1238
+
1059
1239
@Component ( {
1060
1240
template : `
1061
1241
<igx-tree-grid #treeGrid [data]="data" primaryKey="employeeID" foreignKey="PID" width="900px" height="500px" [rowDraggable]="true">
0 commit comments