Skip to content

Commit 075bfee

Browse files
authored
Merge pull request #10506 from IgniteUI/rkaraivanov/column-moving-grid-prop
refactor: Column moving behavior
2 parents 826242c + 3d6fc44 commit 075bfee

File tree

85 files changed

+1026
-728
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1026
-728
lines changed

Diff for: CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
All notable changes for each version of this project will be documented in this file.
44

5+
## 13.1.0
6+
7+
### General
8+
9+
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
10+
- **Breaking Change** - `movable` property of `IgxColumnComponent` is now deprecated and will be removed in future version. Instead, use the newly exposed `moving` property on grid-level:
11+
```html
12+
<igx-grid [data]="data" [moving]="true">
13+
<igx-column field="Name"></igx-column>
14+
<igx-column field="Age"></igx-column>
15+
</igx-grid>
16+
```
17+
518
## 13.0.5
619

720
### New Features

Diff for: projects/igniteui-angular/migrations/migration-collection.json

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
"version": "13.0.0-alpha",
111111
"description": "Updates Ignite UI for Angular from v12.2.x to v13.0.0",
112112
"factory": "./update-13_0_0"
113+
},
114+
"migration-23": {
115+
"version": "13.1.0",
116+
"description": "Updates Ignite UI for Angular from v13.0.x to v13.1.0",
117+
"factory": "./update-13_1_0"
113118
}
114119
}
115120
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import * as path from 'path';
2+
3+
import { EmptyTree } from '@angular-devkit/schematics';
4+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
5+
6+
const version = '13.1.0';
7+
8+
describe(`Update to ${version}`, () => {
9+
let appTree: UnitTestTree;
10+
const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json'));
11+
const configJson = {
12+
defaultProject: 'testProj',
13+
projects: {
14+
testProj: {
15+
sourceRoot: '/testSrc'
16+
}
17+
},
18+
schematics: {
19+
'@schematics/angular:component': {
20+
prefix: 'appPrefix'
21+
}
22+
}
23+
};
24+
25+
beforeEach(() => {
26+
appTree = new UnitTestTree(new EmptyTree());
27+
appTree.create('/angular.json', JSON.stringify(configJson));
28+
});
29+
30+
const migrationName = 'migration-23';
31+
32+
it('should remove columns` movable prop and enable grid`s moving prop if there is movable columns', async () => {
33+
appTree.create(
34+
`/testSrc/appPrefix/component/test.component.html`,
35+
`
36+
<igx-grid>
37+
<igx-column [movable]="true"></igx-column>
38+
<igx-column></igx-column>
39+
</igx-grid>
40+
`
41+
);
42+
43+
const tree = await schematicRunner
44+
.runSchematicAsync(migrationName, {}, appTree)
45+
.toPromise();
46+
47+
expect(
48+
tree.readContent('/testSrc/appPrefix/component/test.component.html')
49+
).toEqual(
50+
`
51+
<igx-grid [moving]="true">
52+
<igx-column ></igx-column>
53+
<igx-column></igx-column>
54+
</igx-grid>
55+
`
56+
);
57+
});
58+
59+
it('should remove columns` movable prop and don`t set the grid`s moving prop if there isn`t movable columns', async () => {
60+
appTree.create(
61+
`/testSrc/appPrefix/component/test.component.html`,
62+
`
63+
<igx-grid>
64+
<igx-column [movable]="false"></igx-column>
65+
<igx-column></igx-column>
66+
</igx-grid>
67+
`
68+
);
69+
70+
const tree = await schematicRunner
71+
.runSchematicAsync(migrationName, {}, appTree)
72+
.toPromise();
73+
74+
expect(
75+
tree.readContent('/testSrc/appPrefix/component/test.component.html')
76+
).toEqual(
77+
`
78+
<igx-grid>
79+
<igx-column ></igx-column>
80+
<igx-column></igx-column>
81+
</igx-grid>
82+
`
83+
);
84+
});
85+
86+
87+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Element } from '@angular/compiler';
2+
import {
3+
Rule,
4+
SchematicContext,
5+
Tree
6+
} from '@angular-devkit/schematics';
7+
import { UpdateChanges } from '../common/UpdateChanges';
8+
import { nativeImport } from '../common/import-helper.js';
9+
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile } from '../common/util';
10+
11+
const version = '13.1.0';
12+
13+
export default (): Rule => async (host: Tree, context: SchematicContext) => {
14+
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
15+
const { HtmlParser } = await nativeImport('@angular/compiler') as typeof import('@angular/compiler');
16+
17+
const update = new UpdateChanges(__dirname, host, context);
18+
const GRID_TAGS = ['igx-grid', 'igx-tree-grid', 'igx-hierarchical-grid', 'igx-row-island'];
19+
const prop = ['[movable]'];
20+
const changes = new Map<string, FileChange[]>();
21+
22+
const gridsToMigrate = new Set<any>();
23+
24+
const applyChanges = () => {
25+
for (const [path, change] of changes.entries()) {
26+
let buffer = host.read(path).toString();
27+
28+
change.sort((c, c1) => c.position - c1.position)
29+
.reverse()
30+
.forEach(c => buffer = c.apply(buffer));
31+
32+
host.overwrite(path, buffer);
33+
}
34+
};
35+
36+
const addChange = (path: string, change: FileChange) => {
37+
if (changes.has(path)) {
38+
changes.get(path).push(change);
39+
} else {
40+
changes.set(path, [change]);
41+
}
42+
};
43+
44+
// migrate movable on column-level to moving on grid-level for grid, tree grid, hierarchical grid and row island
45+
for (const path of update.templateFiles) {
46+
const grids = findElementNodes(parseFile(new HtmlParser(), host, path), GRID_TAGS);
47+
grids.forEach(grid => {
48+
const grid_elem = grid as Element;
49+
const columns = grid_elem.children.filter(column => (column as Element).name === 'igx-column' && hasAttribute(column as Element, prop));
50+
columns.map(node => getSourceOffset(node as Element))
51+
.forEach(offset => {
52+
const { startTag, file, node } = offset;
53+
const { name, value } = getAttribute(node, prop)[0];
54+
if (value === 'true') {
55+
gridsToMigrate.add(grid_elem);
56+
}
57+
const repTxt = file.content.substring(startTag.start, startTag.end);
58+
const property = `${name}="${value}"`;
59+
const removePropTxt = repTxt.replace(property, '');
60+
addChange(file.url, new FileChange(startTag.start, removePropTxt, repTxt, 'replace'));
61+
});
62+
});
63+
64+
Array.from(gridsToMigrate).map(node => getSourceOffset(node as Element)).forEach(offset => {
65+
const { startTag, file } = offset;
66+
addChange(file.url, new FileChange(startTag.end - 1, ' [moving]="true"'));
67+
});
68+
}
69+
70+
applyChanges();
71+
changes.clear();
72+
};

Diff for: projects/igniteui-angular/src/lib/grids/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Below is the list of all inputs that the developers may set to configure the gri
167167
|`resourceStrings`| IGridResourceStrings | Resource strings of the grid. |
168168
|`autoGenerate`|boolean|Autogenerate grid's columns, default value is _false_|
169169
|`batchEditing`|boolean|Toggles batch editing in the grid, default is _false_|
170+
|`moving`|boolean|Enables the columns moving feature. Defaults to _false_|
170171
|`paging`|boolean|Enables the paging feature. Defaults to _false_.|
171172
|`page`| number | The current page index.|
172173
|`perPage`|number|Visible items per page, default is 15|
@@ -333,7 +334,6 @@ Inputs available on the **IgxGridColumnComponent** to define columns:
333334
|`hasSummary`| boolean |Sets whether or not the specific column has summaries enabled.|
334335
|`summaries`| IgxSummaryOperand |Set custom summary for the specific column|
335336
|`hidden`|boolean|Visibility of the column|
336-
|`movable`|boolean|Set column to be movable|
337337
|`resizable`|boolean|Set column to be resizable|
338338
|`selectable`|boolean|Set column to be selectable|
339339
|`selected`|boolean|Set column to be selected|

Diff for: projects/igniteui-angular/src/lib/grids/columns/column-layout.component.ts

-4
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ export class IgxColumnLayoutComponent extends IgxColumnGroupComponent implements
122122
} else {
123123
this.children.forEach(child => child.hidden = this.hidden);
124124
}
125-
126-
this.children.forEach(child => {
127-
child.movable = false;
128-
});
129125
}
130126

131127
/*

Diff for: projects/igniteui-angular/src/lib/grids/columns/column.component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,11 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
422422
@Input()
423423
public disablePinning = false;
424424
/**
425+
* @deprecated in version 13.1.0. Use `IgxGridComponent.moving` instead.
426+
*
425427
* Sets/gets whether the column is movable.
426428
* Default value is `false`.
429+
*
427430
* ```typescript
428431
* let isMovable = this.column.movable;
429432
* ```
@@ -433,8 +436,6 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
433436
*
434437
* @memberof IgxColumnComponent
435438
*/
436-
@WatchColumnChanges()
437-
@notifyChanges()
438439
@Input()
439440
public movable = false;
440441
/**

Diff for: projects/igniteui-angular/src/lib/grids/common/grid.interface.ts

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export interface ColumnType {
143143
resizable: boolean;
144144
searchable: boolean;
145145
columnGroup: boolean;
146+
/** @deprecated in version 13.1.0. Use `IgxGridComponent.moving` instead.*/
146147
movable: boolean;
147148
groupable: boolean;
148149
sortable: boolean;
@@ -267,6 +268,7 @@ export interface GridType extends IGridDataBindable {
267268
pipeTrigger: number;
268269
summaryPipeTrigger: number;
269270
hasColumnLayouts: boolean;
271+
moving: boolean;
270272
isLoading: boolean;
271273
dataCloneStrategy: IDataCloneStrategy;
272274

Diff for: projects/igniteui-angular/src/lib/grids/filtering/excel-style/grid.excel-style-filtering.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<igx-excel-style-sorting *ngIf="column?.sortable">
1010
</igx-excel-style-sorting>
1111

12-
<igx-excel-style-moving *ngIf="column?.movable">
12+
<igx-excel-style-moving *ngIf="grid?.moving">
1313
</igx-excel-style-moving>
1414

1515
<igx-excel-style-pinning *ngIf="!column?.disablePinning && displayDensity==='comfortable'">

Diff for: projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
189189
@Input()
190190
public autoGenerate = false;
191191

192+
/**
193+
* Controls whether columns moving is enabled in the grid.
194+
*
195+
*/
196+
@Input()
197+
public moving = false;
198+
192199
/**
193200
* Gets/Sets a custom template when empty.
194201
*
@@ -4879,13 +4886,16 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
48794886
/**
48804887
* Returns if the `IgxGridComponent` has moveable columns.
48814888
*
4889+
* @deprecated
4890+
* Use `IgxGridComponent.moving` instead.
4891+
*
48824892
* @example
48834893
* ```typescript
48844894
* const movableGrid = this.grid.hasMovableColumns;
48854895
* ```
48864896
*/
48874897
public get hasMovableColumns(): boolean {
4888-
return this.columnList && this.columnList.some((col) => col.movable);
4898+
return this.moving;
48894899
}
48904900

48914901
/**

Diff for: projects/igniteui-angular/src/lib/grids/grid/cell.spec.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,10 @@ describe('IgxGrid - Cell component #grid', () => {
424424
});
425425
@Component({
426426
template: `
427-
<igx-grid #grid [data]="data" [primaryKey]="'ProductID'" [width]="'900px'" [height]="'500px'" rowSelection = "multiple">
427+
<igx-grid #grid [data]="data" [primaryKey]="'ProductID'" [width]="'900px'" [height]="'500px'" rowSelection = "multiple" [moving]="true">
428428
<igx-column *ngFor="let c of columns" [field]="c.field"
429429
[header]="c.field"
430-
[width]="c.width"
431-
[movable]="true"
430+
[width]="c.width"
432431
[groupable]="true"
433432
[resizable]="true"
434433
[sortable]="true"

Diff for: projects/igniteui-angular/src/lib/grids/grid/column-moving.spec.ts

+4-28
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe('IgxGrid - Column Moving #grid', () => {
4848
fixture = TestBed.createComponent(MovableColumnsComponent);
4949
fixture.detectChanges();
5050
grid = fixture.componentInstance.grid;
51+
grid.moving = true;
5152
}));
5253

5354
it('Should be able to reorder columns.', (() => {
@@ -264,33 +265,6 @@ describe('IgxGrid - Column Moving #grid', () => {
264265
expect(grid.getCellByColumn(0, 'ID').selected).toBeTruthy();
265266
}));
266267

267-
268-
269-
it('Should reorder only movable columns when dropping the ghost image on an interactive area.', (async () => {
270-
const headers: DebugElement[] = fixture.debugElement.queryAll(By.css(COLUMN_HEADER_CLASS));
271-
272-
expect(grid.columnList.get(0).movable).toBeTruthy();
273-
expect(grid.columnList.get(2).movable).toBeFalsy();
274-
275-
// step 1 - verify columns are not reordered when
276-
// moving a column that is not movable
277-
const header = headers[2].nativeElement;
278-
UIInteractions.simulatePointerEvent('pointerdown', header, 450, 75);
279-
await wait();
280-
UIInteractions.simulatePointerEvent('pointermove', header, 455, 81);
281-
await wait(50);
282-
UIInteractions.simulatePointerEvent('pointermove', header, 100, 75);
283-
await wait();
284-
UIInteractions.simulatePointerEvent('pointerup', header, 100, 75);
285-
await wait();
286-
fixture.detectChanges();
287-
288-
const columnsList = grid.columnList;
289-
expect(columnsList.get(0).field).toEqual('ID');
290-
expect(columnsList.get(1).field).toEqual('Name');
291-
expect(columnsList.get(2).field).toEqual('LastName');
292-
}));
293-
294268
it('Should not reorder columns when dropping the ghost image on a non-interactive area.', (async () => {
295269
const headers: DebugElement[] = fixture.debugElement.queryAll(By.css(COLUMN_HEADER_CLASS));
296270

@@ -735,6 +709,7 @@ describe('IgxGrid - Column Moving #grid', () => {
735709
fixture = TestBed.createComponent(MovableTemplatedColumnsComponent);
736710
fixture.detectChanges();
737711
grid = fixture.componentInstance.grid;
712+
grid.moving = true;
738713
}));
739714

740715
it('Should reorder movable columns with templated headers.', (async () => {
@@ -771,6 +746,7 @@ describe('IgxGrid - Column Moving #grid', () => {
771746
fixture = TestBed.createComponent(MovableColumnsLargeComponent);
772747
fixture.detectChanges();
773748
grid = fixture.componentInstance.grid;
749+
grid.moving = true;
774750
}));
775751

776752
it('Should be able to scroll forwards to reorder columns that are out of view.', (async () => {
@@ -1304,7 +1280,6 @@ describe('IgxGrid - Column Moving #grid', () => {
13041280
}));
13051281

13061282
it('Pinning - Should not be able to pin a column programmaticaly if disablePinning is enabled for that column', (async () => {
1307-
const columnsList = grid.columnList;
13081283

13091284
// step 1 - pin some columns
13101285
grid.getColumnByName('Address').pinned = true;
@@ -1398,6 +1373,7 @@ describe('IgxGrid - Column Moving #grid', () => {
13981373
fixture = TestBed.createComponent(MultiColumnHeadersComponent);
13991374
fixture.detectChanges();
14001375
grid = fixture.componentInstance.grid;
1376+
grid.moving = true;
14011377
}));
14021378

14031379
it('MCH - should reorder only columns on the same level (top level simple column).', (async () => {

Diff for: projects/igniteui-angular/src/lib/grids/grid/column-selection.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1091,8 +1091,6 @@ describe('IgxGrid - Column Selection #grid', () => {
10911091
});
10921092

10931093
it('Moving: Verify that when move a column, it stays selected', () => {
1094-
colProductID.movable = true;
1095-
colProductName.movable = true;
10961094
colProductID.selected = true;
10971095
fix.detectChanges();
10981096

0 commit comments

Comments
 (0)