Skip to content

Commit a900f82

Browse files
committed
feat(igxGrid): column moving initial integration #935
1 parent 33a43f5 commit a900f82

File tree

6 files changed

+86
-56
lines changed

6 files changed

+86
-56
lines changed

projects/igniteui-angular/src/lib/core/styles/components/grid/_grid-component.scss

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@
193193
@extend %grid__drag-ghost-image !optional;
194194
}
195195

196+
@include e(drag-ghost-group-image) {
197+
@extend %grid__drag-ghost-group-image !optional;
198+
}
199+
196200
@include e(drag-ghost-image-icon) {
197201
@extend %grid__drag-ghost-image-icon !optional;
198202
}

projects/igniteui-angular/src/lib/core/styles/components/grid/_grid-theme.scss

+15-1
Original file line numberDiff line numberDiff line change
@@ -578,21 +578,35 @@
578578
color: --var($theme, 'ghost-header-text-color');
579579
position: absolute;
580580
z-index: 20;
581-
height: auto;
582581
top: -99999px;
583582
left: -99999px;
584583
overflow: visible;
584+
display: table;
585585
box-shadow: igx-elevation($elevations, 5);
586586

587587
%grid-cell-header-title {
588588
min-width: rem(24px);
589589
}
590590
}
591591

592+
%grid__drag-ghost-group-image {
593+
background-color: --var($theme, 'ghost-header-background');
594+
color: --var($theme, 'ghost-header-text-color');
595+
box-shadow: igx-elevation($elevations, 5);
596+
display: table;
597+
padding: map-get($grid-cell-padding, 'comfortable');
598+
599+
%grid-cell-header-title {
600+
min-width: rem(24px);
601+
}
602+
}
603+
592604
%grid__drag-ghost-image-icon {
593605
color: --var($theme, 'ghost-header-icon-color');
594606
font-size: rem(24px);
595607
margin-right: rem(8);
608+
justify-content: center;
609+
align-items: center;
596610
}
597611

598612
%igx-grid__drag-col-header {

projects/igniteui-angular/src/lib/grid/grid-header.component.html

+25-20
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
</ng-template>
44

55
<ng-container *ngIf="column.columnGroup">
6+
<span *ngIf="grid.hasMovableColumns" class="igx-grid__th-drop-indicator-left">
7+
</span>
68
<div style="display: block; height: 50px; text-align: center; border-bottom: 1px solid #ddd; border-right: 1px solid #ddd;">{{ column.header }}</div>
79
<div style="display: flex; flex-flow: row;">
810
<ng-container *ngFor="let child of column.children">
9-
<igx-grid-header *ngIf="!child.hidden" [gridID]="column.gridID" [column]="child" [style.min-width.px]="child.width" [style.flex-basis.px]='child.width'></igx-grid-header>
11+
<igx-grid-header [igxColumnMovingDrag]="child" [attr.droppable]="true" [igxColumnMovingDrop]="child" *ngIf="!child.hidden" [gridID]="column.gridID" [column]="child" [style.min-width.px]="child.width" [style.flex-basis.px]='child.width'></igx-grid-header>
1012
</ng-container>
1113
</div>
14+
<span *ngIf="grid.hasMovableColumns" class="igx-grid__th-drop-indicator-right">
15+
</span>
1216
</ng-container>
1317
<ng-container *ngIf="!column.columnGroup">
1418
<span *ngIf="grid.hasMovableColumns" class="igx-grid__th-drop-indicator-left">
@@ -17,27 +21,28 @@
1721
<ng-container *ngTemplateOutlet="column.headerTemplate ? column.headerTemplate : defaultColumn; context: { $implicit: column }">
1822
</ng-container>
1923
</span>
20-
</ng-container>
24+
<div class="igx-grid__th-icons" *ngIf="!column.columnGroup">
25+
<igx-icon class="sort-icon" *ngIf="column.sortable">{{sortingIcon}}</igx-icon>
26+
<igx-grid-filter [column]="column" *ngIf="column.filterable"></igx-grid-filter>
27+
</div>
2128

22-
<div class="igx-grid__th-icons" *ngIf="!column.columnGroup">
23-
<igx-icon class="sort-icon" *ngIf="column.sortable">{{sortingIcon}}</igx-icon>
24-
<igx-grid-filter [column]="column" *ngIf="column.filterable"></igx-grid-filter>
25-
</div>
29+
<span *ngIf="!column.columnGroup" id="resizeHandler" [style.cursor]="resizeCursor" #resizeArea
30+
class="igx-grid__th-resize-handle"
31+
(dblclick)="onResizeAreaDblClick()">
2632

27-
<span *ngIf="!column.columnGroup" [style.cursor]="resizeCursor" #resizeArea
28-
class="igx-grid__th-resize-handle"
29-
(dblclick)="onResizeAreaDblClick()">
33+
<div *ngIf="showResizer" igxResizer
34+
class="igx-grid__th-resize-line"
35+
[style.height.px]="resizerHeight"
36+
[restrictHResizeMax]="restrictResizeMax"
37+
[restrictHResizeMin]="restrictResizeMin"
38+
[resizeEndTimeout]="resizeEndTimeout"
39+
(resizeEnd)="onResize($event)">
40+
</div>
3041

31-
<div *ngIf="showResizer" igxResizer
32-
class="igx-grid__th-resize-line"
33-
[style.height.px]="resizerHeight"
34-
[restrictHResizeMax]="restrictResizeMax"
35-
[restrictHResizeMin]="restrictResizeMin"
36-
[resizeEndTimeout]="resizeEndTimeout"
37-
(resizeEnd)="onResize($event)">
38-
</div>
42+
</span>
43+
44+
<span *ngIf="grid.hasMovableColumns" class="igx-grid__th-drop-indicator-right">
45+
</span>
46+
</ng-container>
3947

40-
</span>
4148

42-
<span *ngIf="grid.hasMovableColumns" class="igx-grid__th-drop-indicator-right">
43-
</span>

projects/igniteui-angular/src/lib/grid/grid.common.ts

+34-27
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,10 @@ export class IgxColumnMovingDragDirective extends IgxDragDirective {
251251
}
252252

253253
public onPointerDown(event) {
254+
event.stopPropagation();
254255

255-
const resizeArea = document.elementFromPoint(event.pageX, event.pageY);
256-
if (!this.draggable || this.element.nativeElement.children[3].isEqualNode(resizeArea)) {
256+
const el = document.elementFromPoint(event.pageX, event.pageY);
257+
if (!this.draggable || el.getAttribute("id") === "resizeHandler") {
257258
return;
258259
}
259260

@@ -270,6 +271,7 @@ export class IgxColumnMovingDragDirective extends IgxDragDirective {
270271
}
271272

272273
public onPointerMove(event) {
274+
event.preventDefault();
273275

274276
if (!this.draggable) {
275277
return;
@@ -296,7 +298,9 @@ export class IgxColumnMovingDragDirective extends IgxDragDirective {
296298

297299
protected createDragGhost(event) {
298300
super.createDragGhost(event);
299-
this._dragGhost.removeChild(this._dragGhost.children[2]);
301+
302+
this._dragGhost.style.minWidth = null;
303+
this._dragGhost.style.flexBasis = null;
300304

301305
const icon = document.createElement('i');
302306
const text = document.createTextNode('swap_horiz');
@@ -305,25 +309,23 @@ export class IgxColumnMovingDragDirective extends IgxDragDirective {
305309
icon.classList.add('material-icons');
306310
this.renderer.addClass(icon, this._dragGhostImgIconClass);
307311

308-
this._dragGhost.insertBefore(icon, this._dragGhost.children[1]);
309-
310312
this.cms.icon = icon;
311313

312-
this._dragGhost.style.minWidth = null;
313-
this._dragGhost.style.flexBasis = null;
314-
315-
const range = document.createRange();
316-
range.selectNodeContents(this._dragGhost.children[2]);
314+
if (!this.column.columnGroup) {
315+
this._dragGhost.removeChild(this._dragGhost.children[2]);
316+
this._dragGhost.insertBefore(icon, this._dragGhost.children[1]);
317317

318-
const s = document.defaultView.getComputedStyle(this.element.nativeElement);
319-
this._dragGhost.style.width = Math.ceil(range.getBoundingClientRect().width +
320-
parseFloat(s.borderRightWidth) + parseFloat(s.borderLeftWidth) + parseFloat(s.paddingLeft) +
321-
parseFloat(s.paddingRight) + icon.getBoundingClientRect().width) +
322-
parseFloat(document.defaultView.getComputedStyle(icon).marginRight) + 'px';
318+
this.left = this._dragStartX = event.clientX - ((this._dragGhost.getBoundingClientRect().width / 3) * 2);
319+
this.top = this._dragStartY = event.clientY - ((this._dragGhost.getBoundingClientRect().height / 3) * 2);
320+
} else {
321+
this._dragGhost.removeChild(this._dragGhost.children[2]);
322+
this._dragGhost.removeChild(this._dragGhost.children[0]);
323+
this._dragGhost.removeChild(this._dragGhost.children[this._dragGhost.children.length - 1]);
324+
this.renderer.addClass(this._dragGhost.children[0], 'igx-grid__drag-ghost-group-image');
323325

324-
this.left = this._dragStartX = event.clientX -
325-
(((range.getBoundingClientRect().width + parseFloat(s.paddingLeft) + parseFloat(s.paddingRight)) / 3) * 2);
326-
this.top = this._dragStartY = event.clientY - ((parseFloat(s.height) / 3) * 2);
326+
this.left = this._dragStartX = event.clientX - ((this._dragGhost.getBoundingClientRect().width / 3) * 2);
327+
this.top = this._dragStartY = event.clientY - ((this._dragGhost.getBoundingClientRect().height / 3) * 2);
328+
}
327329
}
328330
}
329331

@@ -372,7 +374,10 @@ export class IgxColumnMovingDropDirective extends IgxDropDirective implements On
372374
}
373375

374376
public onDragEnter(event) {
375-
if (this.isDropTarget && this.cms.column !== this.column) {
377+
if (this.isDropTarget &&
378+
this.cms.column !== this.column &&
379+
this.cms.column.level === this.column.level &&
380+
this.cms.column.parent === this.column.parent) {
376381
const args = {
377382
source: this.cms.column,
378383
target: this.column,
@@ -386,8 +391,8 @@ export class IgxColumnMovingDropDirective extends IgxDropDirective implements On
386391
}
387392

388393
if (!this.column.pinned || (this.column.pinned && this.cms.column.pinned)) {
389-
this._dropIndicator = this.cms.column.index < this.column.index ? this.elementRef.nativeElement.children[4] :
390-
this.elementRef.nativeElement.children[0];
394+
this._dropIndicator = this.cms.column.index < this.column.index ? this.elementRef.nativeElement.lastElementChild :
395+
this.elementRef.nativeElement.firstElementChild;
391396

392397
this.renderer.addClass(this._dropIndicator, this._dropIndicatorClass);
393398

@@ -398,16 +403,16 @@ export class IgxColumnMovingDropDirective extends IgxDropDirective implements On
398403
const nextPinnedWidth = this.column.grid.getPinnedWidth() + parseFloat(this.cms.column.width);
399404

400405
if (nextPinnedWidth <= this.column.grid.calcPinnedContainerMaxWidth) {
401-
this._dropIndicator = this.elementRef.nativeElement.children[0];
402-
this.renderer.addClass(this._dropIndicator, this._dropIndicatorClass);
403-
404406
this.cms.icon.innerText = 'lock';
407+
408+
this._dropIndicator = this.elementRef.nativeElement.firstElementChild;
409+
this.renderer.addClass(this._dropIndicator, this._dropIndicatorClass);
405410
} else {
406411
this.cms.icon.innerText = 'block';
407412
}
408413
}
409414
} else {
410-
this.cms.icon.innerText = 'swap_horiz';
415+
this.cms.icon.innerText = 'block';
411416
}
412417

413418
if (this.horizontalScroll) {
@@ -462,8 +467,10 @@ export class IgxColumnMovingDropDirective extends IgxDropDirective implements On
462467
nextPinnedWidth = this.column.grid.getPinnedWidth() + parseFloat(this.cms.column.width);
463468
}
464469

465-
if (args.cancel || (nextPinnedWidth && nextPinnedWidth > this.column.grid.calcPinnedContainerMaxWidth)) {
466-
return;
470+
if (args.cancel || (nextPinnedWidth && nextPinnedWidth > this.column.grid.calcPinnedContainerMaxWidth) ||
471+
this.column.level !== this.cms.column.level ||
472+
this.column.parent !== this.cms.column.parent) {
473+
return;
467474
}
468475

469476
this.column.grid.moveColumn(this.cms.column, this.column);

src/app/grid-column-groups/grid-column-groups.sample.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<app-page-header title="Grid Column Groups"></app-page-header>
33
<section class="sample-content">
44
<igx-grid [rowSelectable]="false" #grid height="600px" [data]="data" displayDensity="compact">
5-
<igx-column [pinned]="true" field="Missing"></igx-column>
6-
<igx-column field="ID"></igx-column>
7-
<igx-column-group [pinned]="true" header="General Information">
8-
<igx-column filterable="true" sortable="true" resizable="true" field="CompanyName"></igx-column>
9-
<igx-column-group header="Person Details">
10-
<igx-column [pinned]="true" filterable="true" sortable="true" resizable="true" field="ContactName"></igx-column>
11-
<igx-column filterable="true" sortable="true" resizable="true" field="ContactTitle"></igx-column>
5+
<igx-column [movable]="true" [resizable]="true" [pinned]="true" field="Missing"></igx-column>
6+
<igx-column [movable]="true" [resizable]="true" field="ID"></igx-column>
7+
<igx-column-group [movable]="true" [pinned]="true" header="General Information">
8+
<igx-column [movable]="true" filterable="true" sortable="true" resizable="true" field="CompanyName"></igx-column>
9+
<igx-column-group [movable]="true" header="Person Details">
10+
<igx-column [movable]="true" [pinned]="true" filterable="true" sortable="true" resizable="true" field="ContactName"></igx-column>
11+
<igx-column [movable]="true" filterable="true" sortable="true" resizable="true" field="ContactTitle"></igx-column>
1212
</igx-column-group>
1313
</igx-column-group>
1414
<igx-column-group header="Address Information">

src/app/grid-column-moving/grid-column-moving.sample.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export class GridColumnMovingSampleComponent implements OnInit {
385385

386386
toggleColumn(name: string) {
387387
const col = this.grid1.getColumnByName(name);
388-
col.pinned ? col.unpin() : col.pin();
388+
col.pinned ? col.pinned = false : col.pinned = true;
389389
}
390390

391391
onColumnMovingStart(event) {

0 commit comments

Comments
 (0)