Skip to content

Commit f48b1a2

Browse files
committed
Merge branch 'pivot-grid-master' into skrastev/pivot-grid-resize
2 parents 0b18bcf + 0b84427 commit f48b1a2

File tree

7 files changed

+53
-26
lines changed

7 files changed

+53
-26
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<ng-container *ngIf="!isHeader && !singleMode">
2-
<igx-checkbox [checked]="selected" [disableRipple]="true" [disableTransitions]="disableTransitions" [tabindex]="-1" (click)="disableCheck($event)" class="igx-combo__checkbox"></igx-checkbox>
2+
<!-- checkbox should not allow changing its state from UI click (that's why it should be readonly=true), becasue when cancelling the selectionChange event in the combo, then checkbox will still change state.-->
3+
<igx-checkbox [checked]="selected" [readonly]="true" [disableRipple]="true" [disableTransitions]="disableTransitions" [tabindex]="-1" (click)="disableCheck($event)" class="igx-combo__checkbox"></igx-checkbox>
34
</ng-container>
45
<span class="igx-drop-down__inner"><ng-content></ng-content></span>

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ const CSS_CLASS_INPUT_COSY = 'igx-input-group--cosy';
6565
const CSS_CLASS_INPUT_COMPACT = 'igx-input-group--compact';
6666
const CSS_CLASS_INPUT_COMFORTABLE = 'igx-input-group--comfortable';
6767
const CSS_CLASS_EMPTY = 'igx-combo__empty';
68+
const CSS_CLASS_ITEM_CHECKBOX = 'igx-combo__checkbox';
69+
const CSS_CLASS_ITME_CHECKBOX_CHECKED = 'igx-checkbox--checked';
6870
const defaultDropdownItemHeight = 40;
6971
const defaultDropdownItemMaxHeight = 400;
7072

@@ -1927,12 +1929,19 @@ describe('igxCombo', () => {
19271929
combo = fixture.componentInstance.combo;
19281930
input = fixture.debugElement.query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
19291931
});
1930-
const simulateComboItemCheckboxClick = (itemIndex: number, isHeader = false) => {
1932+
const simulateComboItemClick = (itemIndex: number, isHeader = false) => {
19311933
const itemClass = isHeader ? CSS_CLASS_HEADERITEM : CSS_CLASS_DROPDOWNLISTITEM;
19321934
const dropdownItem = fixture.debugElement.queryAll(By.css('.' + itemClass))[itemIndex];
19331935
dropdownItem.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
19341936
fixture.detectChanges();
19351937
};
1938+
const simulateComboItemCheckboxClick = (itemIndex: number, isHeader = false) => {
1939+
const itemClass = isHeader ? CSS_CLASS_HEADERITEM : CSS_CLASS_DROPDOWNLISTITEM;
1940+
const dropdownItem = fixture.debugElement.queryAll(By.css('.' + itemClass))[itemIndex];
1941+
const itemCheckbox = dropdownItem.query(By.css('.' + CSS_CLASS_ITEM_CHECKBOX));
1942+
itemCheckbox.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
1943+
fixture.detectChanges();
1944+
};
19361945
it('should append/remove selected items to the input in their selection order', () => {
19371946
let expectedOutput = 'Illinois';
19381947
combo.select(['Illinois']);
@@ -2028,7 +2037,7 @@ describe('igxCombo', () => {
20282037
fixture.detectChanges();
20292038

20302039
const selectedItem_1 = dropdown.items[1];
2031-
simulateComboItemCheckboxClick(1);
2040+
simulateComboItemClick(1);
20322041
expect(combo.selection[0]).toEqual(selectedItem_1.value.field);
20332042
expect(selectedItem_1.selected).toBeTruthy();
20342043
expect(selectedItem_1.element.nativeElement.classList.contains(CSS_CLASS_SELECTED)).toBeTruthy();
@@ -2046,7 +2055,7 @@ describe('igxCombo', () => {
20462055
});
20472056

20482057
const selectedItem_2 = dropdown.items[5];
2049-
simulateComboItemCheckboxClick(5);
2058+
simulateComboItemClick(5);
20502059
expect(combo.selection[1]).toEqual(selectedItem_2.value.field);
20512060
expect(selectedItem_2.selected).toBeTruthy();
20522061
expect(selectedItem_2.element.nativeElement.classList.contains(CSS_CLASS_SELECTED)).toBeTruthy();
@@ -2065,7 +2074,7 @@ describe('igxCombo', () => {
20652074

20662075
// Unselecting an item
20672076
const unselectedItem = dropdown.items[1];
2068-
simulateComboItemCheckboxClick(1);
2077+
simulateComboItemClick(1);
20692078
expect(combo.selection.length).toEqual(1);
20702079
expect(unselectedItem.selected).toBeFalsy();
20712080
expect(unselectedItem.element.nativeElement.classList.contains(CSS_CLASS_SELECTED)).toBeFalsy();
@@ -2087,10 +2096,26 @@ describe('igxCombo', () => {
20872096
combo.toggle();
20882097
fixture.detectChanges();
20892098

2090-
simulateComboItemCheckboxClick(0, true);
2099+
simulateComboItemClick(0, true);
20912100
expect(combo.selection.length).toEqual(0);
20922101
expect(combo.selectionChanging.emit).toHaveBeenCalledTimes(0);
20932102
});
2103+
it('should prevent selection when selectionChanging is cancelled', () => {
2104+
spyOn(combo.selectionChanging, 'emit').and.callFake((event: IComboSelectionChangingEventArgs) => event.cancel = true);
2105+
combo.toggle();
2106+
fixture.detectChanges();
2107+
2108+
const dropdownFirstItem = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_DROPDOWNLISTITEM}`))[0].nativeElement;
2109+
const itemCheckbox = dropdownFirstItem.querySelectorAll(`.${CSS_CLASS_ITEM_CHECKBOX}`);
2110+
2111+
simulateComboItemCheckboxClick(0);
2112+
expect(combo.selection.length).toEqual(0);
2113+
expect(itemCheckbox[0].classList.contains(CSS_CLASS_ITME_CHECKBOX_CHECKED)).toBeFalsy();
2114+
2115+
simulateComboItemClick(0);
2116+
expect(combo.selection.length).toEqual(0);
2117+
expect(itemCheckbox[0].classList.contains(CSS_CLASS_ITME_CHECKBOX_CHECKED)).toBeFalsy();
2118+
});
20942119
});
20952120
describe('Grouping tests: ', () => {
20962121
configureTestSuite();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6758,7 +6758,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
67586758

67596759
// eslint-disable-next-line prefer-const
67606760
for (let [row, set] of selectionMap) {
6761-
row = this.paginator && source === this.filteredSortedData ? row + (this.paginator.perPage * this.paginator.page) : row;
6761+
row = this.paginator && (this.pagingMode === GridPagingMode.Local && source === this.filteredSortedData) ? row + (this.paginator.perPage * this.paginator.page) : row;
67626762
row = isRemote ? row - this.virtualizationState.startIndex : row;
67636763
if (!source[row] || source[row].detailsData !== undefined) {
67646764
continue;

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,26 +275,19 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
275275
.concat(this.grid.pivotConfiguration.columns)
276276
.concat(this.grid.pivotConfiguration.filters);
277277
// chip moved from external collection
278-
const dims = allDims.filter(x => x && x.memberName === dragId);
279-
if (dims.length === 0) {
278+
const dim = allDims.find(x => x && x.memberName === dragId);
279+
if (!dim) {
280280
// you have dragged something that is not a dimension
281281
return;
282282
}
283-
dims.forEach(element => {
284-
element.enabled = false;
285-
});
283+
const dimType = this.getDimensionsType(dim);
284+
285+
// Dragged chip from a different dimension to the current one.
286+
const prevDimensionCollection = this.getDimensionsByType(dimType);
287+
// delete from previous dimension collection and add to current.
288+
prevDimensionCollection.splice(prevDimensionCollection.indexOf(dim), 1);
289+
currentDim.splice(targetIndex, 0, dim);
286290

287-
const currentDimChild = currentDim.find(x => x && x.memberName === dragId);
288-
if (currentDimChild) {
289-
currentDimChild.enabled = true;
290-
const dragChipIndex = currentDim.indexOf(currentDimChild);
291-
currentDim.splice(dragChipIndex, 1);
292-
currentDim.splice(dragChipIndex > chipIndex ? targetIndex : targetIndex - 1, 0, currentDimChild);
293-
} else {
294-
const newDim = Object.assign({}, dims[0]);
295-
newDim.enabled = true;
296-
currentDim.splice(targetIndex, 0, newDim);
297-
}
298291
const isDraggedFromColumn = !!this.grid.pivotConfiguration.columns?.find(x => x && x.memberName === dragId);
299292
if (isDraggedFromColumn) {
300293
// columns have changed.
@@ -341,6 +334,12 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
341334
}
342335
}
343336

337+
protected getDimensionsType(dimension: IPivotDimension) {
338+
const isColumn = !!this.grid.pivotConfiguration.columns?.find(x => x && x.memberName === dimension.memberName);
339+
const isRow = !!this.grid.pivotConfiguration.rows?.find(x => x && x.memberName === dimension.memberName);
340+
return isColumn ? PivotDimensionType.Column : isRow ? PivotDimensionType.Row : PivotDimensionType.Filter;
341+
}
342+
344343
protected getAggregatorsForValue(value: IPivotValue): IPivotAggregator[] {
345344
const dataType = value.dataType || this.grid.resolveDataTypes(this.grid.data[0][value.member]);
346345
switch (dataType) {

src/app/grid-remote-paging/grid-remote-paging.sample.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div class="dark-grid">
2-
<igx-grid igxPreventDocumentScroll #grid1 [data]="data | async" width="100%" height="540px">
2+
<igx-grid igxPreventDocumentScroll #grid1 [data]="data | async" width="100%" height="540px" [batchEditing]="true"
3+
[pagingMode]="mode">
34
<igx-column field="ID"></igx-column>
45
<igx-column field="ProductName"></igx-column>
56
<igx-column field="QuantityPerUnit"></igx-column>

src/app/grid-remote-paging/grid-remote-paging.sample.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
2-
import { IgxGridComponent } from 'igniteui-angular';
2+
import { GridPagingMode, IgxGridComponent } from 'igniteui-angular';
33
import { RemoteService } from '../shared/remote.service';
44
import { Observable } from 'rxjs';
55

@@ -10,6 +10,7 @@ import { Observable } from 'rxjs';
1010
export class GridRemotePagingSampleComponent implements OnInit, AfterViewInit, OnDestroy {
1111
@ViewChild('grid1', { static: true }) public grid1: IgxGridComponent;
1212

13+
public mode: GridPagingMode = GridPagingMode.Remote;
1314
public page = 0;
1415
public totalCount = 0;
1516
public pages = [];

src/app/grid-row-edit/grid-row-edit-sample.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,4 @@ <h4>Performance grid with transactions and row edit</h4>
222222
<button igxButton (click)="toggle.close()">Cancel</button>
223223
</div>
224224
</div>
225-
</div>
225+
</div>

0 commit comments

Comments
 (0)