Skip to content

Commit 402c369

Browse files
authored
Merge branch '9.1.x' into mkirova/fix-5459-9.1.x
2 parents e235787 + 60d0494 commit 402c369

38 files changed

+448
-130
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ All notable changes for each version of this project will be documented in this
129129
```typescript
130130
public pinningConfiguration: IPinningConfig = { columns: ColumnPinningPosition.End };
131131
```
132+
- Added new properties for paging:
133+
- `totalRecords` set to alter the pages count based on total remote records. Keep in mind that If you are using paging and all the data is passed to the grid, the value of totalRecords property will be set by default to the length of the provided data source. If totalRecords is set, it will take precedent over the default length based on the data source.
134+
- `pagingMode` - accepts `GridPagingMode` enumeration. If the paging mode is set to remote the grid will not paginate the passed data source, if the paging mode is set to local (which is the default value) the grid will paginate the data source based on the page, perPage and totalRecords values.
132135
- Added functionality for column selection.
133136
- `columnSelection` property has been added. It accepts GridSelection mode enumeration. Grid selection mode could be none, single or multiple.
134137
- `selected` property has been added to the IgxColumnComponent; Allows you to set whether the column is selected.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,6 @@
957957
width: 100%;
958958
background: --var($theme, 'header-background');
959959
z-index: 10001;
960-
overflow: hidden;
961960
}
962961

963962
%grid-thead-thumb {

projects/igniteui-angular/src/lib/data-operations/data-util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ export class DataUtil {
7272
return grouping.groupBy(data, state, grid, groupsRecords, fullResult);
7373
}
7474

75-
public static page<T>(data: T[], state: IPagingState): T[] {
75+
public static page<T>(data: T[], state: IPagingState, dataLength?: number): T[] {
7676
if (!state) {
7777
return data;
7878
}
79-
const len = data.length;
79+
const len = dataLength !== undefined ? dataLength : data.length;
8080
const index = state.index;
8181
const res = [];
82-
const recordsPerPage = state.recordsPerPage;
82+
const recordsPerPage = dataLength !== undefined && state.recordsPerPage > dataLength ? dataLength : state.recordsPerPage;
8383
state.metadata = {
8484
countPages: 0,
85-
countRecords: data.length,
85+
countRecords: len,
8686
error: PagingError.None
8787
};
8888
if (index < 0 || isNaN(index)) {

projects/igniteui-angular/src/lib/directives/for-of/base.helper.component.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,19 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
5252
public get size() {
5353
return this._size;
5454
}
55+
56+
public get scrollNativeSize() {
57+
const div = document.createElement('div');
58+
const style = div.style;
59+
style.width = '100px';
60+
style.height = '100px';
61+
style.position = 'absolute';
62+
style.top = '-10000px';
63+
style.top = '-10000px';
64+
style.overflow = 'scroll';
65+
document.body.appendChild(div);
66+
const scrollWidth = div.offsetWidth - div.clientWidth;
67+
document.body.removeChild(div);
68+
return scrollWidth ? scrollWidth + 1 : 1;
69+
}
5570
}

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,12 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
709709
return this.sizesCache[index + 1] - this.sizesCache[index];
710710
}
711711

712-
public getScrollbarWidth() {
713-
return this.scrollComponent ? (this.scrollComponent as VirtualHelperComponent).scrollWidth : 0;
712+
/**
713+
* @hidden
714+
* Function that is called to get the native scrollbar size that the browsers renders.
715+
*/
716+
public getScrollNativeSize() {
717+
return this.scrollComponent ? this.scrollComponent.scrollNativeSize : 0;
714718
}
715719

716720
/**

projects/igniteui-angular/src/lib/directives/for-of/virtual.helper.component.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ export class VirtualHelperComponent extends VirtualHelperBaseDirective implement
2525
}
2626

2727
ngOnInit() {
28-
this.scrollWidth = this.getScrollWidth();
28+
this.scrollWidth = this.scrollNativeSize;
2929
}
30-
31-
private getScrollWidth() {
32-
const div = document.createElement('div');
33-
const style = div.style;
34-
style.width = '100px';
35-
style.height = '100px';
36-
style.position = 'absolute';
37-
style.top = '-10000px';
38-
style.top = '-10000px';
39-
style.overflow = 'scroll';
40-
document.body.appendChild(div);
41-
const scrollWidth = div.offsetWidth - div.clientWidth;
42-
document.body.removeChild(div);
43-
return scrollWidth ? scrollWidth + 1 : 0;
44-
}
45-
4630
}

projects/igniteui-angular/src/lib/directives/input/input.directive.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,29 @@ describe('IgxInput', () => {
615615
expect(inputGroup.element.nativeElement.classList.contains(INPUT_GROUP_INVALID_CSS_CLASS)).toBe(false);
616616
expect(inputGroup.element.nativeElement.classList.contains(INPUT_GROUP_VALID_CSS_CLASS)).toBe(false);
617617
});
618+
619+
it('should not set null or undefined as input value', () => {
620+
const fixture = TestBed.createComponent(InputComponent);
621+
fixture.detectChanges();
622+
623+
const igxInput = fixture.componentInstance.igxInput;
624+
expect(igxInput.value).toBe('');
625+
626+
igxInput.value = undefined;
627+
expect(igxInput.value).toBe('');
628+
629+
igxInput.value = null;
630+
expect(igxInput.value).toBe('');
631+
632+
igxInput.value = 0;
633+
expect(igxInput.value).toBe('0');
634+
635+
igxInput.value = false;
636+
expect(igxInput.value).toBe('false');
637+
638+
igxInput.value = 'Test';
639+
expect(igxInput.value).toBe('Test');
640+
});
618641
});
619642

620643
@Component({ template: `

projects/igniteui-angular/src/lib/directives/input/input.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
7474
*/
7575
@Input()
7676
set value(value: any) {
77-
this.nativeElement.value = value;
77+
this.nativeElement.value = value ?? '';
7878
this.checkValidity();
7979
}
8080
/**

projects/igniteui-angular/src/lib/grids/common/enums.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ export enum RowPinningPosition {
4242
Top,
4343
Bottom
4444
}
45+
46+
export enum GridPagingMode {
47+
local,
48+
remote
49+
}

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

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ import {
113113
GridSummaryCalculationMode,
114114
FilterMode,
115115
ColumnPinningPosition,
116-
RowPinningPosition
116+
RowPinningPosition,
117+
GridPagingMode
117118
} from './common/enums';
118119
import {
119120
IGridCellEventArgs,
@@ -173,8 +174,11 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
173174
private _cdrRequests = false;
174175
protected _cdrRequestRepaint = false;
175176

176-
public get scrollWidth() {
177-
return this.verticalScrollContainer.getScrollbarWidth();
177+
/**
178+
* @hidden @internal
179+
*/
180+
public get scrollSize() {
181+
return this.verticalScrollContainer.getScrollNativeSize();
178182
}
179183

180184
private _resourceStrings = CurrentResourceStrings.GridResStrings;
@@ -409,6 +413,17 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
409413
this._locale = value;
410414
}
411415

416+
@Input()
417+
get pagingMode() {
418+
return this._pagingMode;
419+
}
420+
421+
set pagingMode(val: GridPagingMode) {
422+
this._pagingMode = val;
423+
this._pipeTrigger++;
424+
this.notifyChanges(true);
425+
}
426+
412427
/**
413428
* Gets/Sets whether the paging feature is enabled.
414429
* @remarks
@@ -2496,6 +2511,14 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
24962511
* @hidden
24972512
*/
24982513
protected _paging = false;
2514+
/**
2515+
* @hidden
2516+
*/
2517+
protected _pagingMode = GridPagingMode.local;
2518+
/**
2519+
* @hidden @internal
2520+
*/
2521+
public _totalRecords = -1;
24992522
/**
25002523
* @hidden
25012524
*/
@@ -3621,7 +3644,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
36213644
if (this.pagingState) {
36223645
return this.pagingState.metadata.countPages;
36233646
}
3624-
return -1;
3647+
return this._totalRecords >= 0 ? Math.ceil(this._totalRecords / this.perPage) : -1;
36253648
}
36263649

36273650
/**
@@ -3670,9 +3693,16 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
36703693
* const totalRecords = this.grid.totalRecords;
36713694
* ```
36723695
*/
3696+
@Input()
36733697
get totalRecords(): number {
3674-
if (this.pagingState) {
3675-
return this.pagingState.metadata.countRecords;
3698+
return this._totalRecords >= 0 ? this._totalRecords : this.pagingState?.metadata.countRecords;
3699+
}
3700+
3701+
set totalRecords(total: number) {
3702+
if (total >= 0) {
3703+
this._totalRecords = total;
3704+
this._pipeTrigger++;
3705+
this.notifyChanges();
36763706
}
36773707
}
36783708

@@ -4633,9 +4663,9 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
46334663
/**
46344664
* @hidden
46354665
*/
4636-
protected getPagingHeight(): number {
4666+
protected getPagingFooterHeight(): number {
46374667
let pagingHeight = 0;
4638-
if (this.paging && this.footer) {
4668+
if (this.footer) {
46394669
pagingHeight = this.footer.nativeElement.firstElementChild ?
46404670
this.footer.nativeElement.offsetHeight : 0;
46414671
}
@@ -4666,7 +4696,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
46664696
this.theadRow.nativeElement.offsetHeight;
46674697
const footerHeight = this.summariesHeight || this.tfoot.nativeElement.offsetHeight - this.tfoot.nativeElement.clientHeight;
46684698
const toolbarHeight = this.getToolbarHeight();
4669-
const pagingHeight = this.getPagingHeight();
4699+
const pagingHeight = this.getPagingFooterHeight();
46704700
const groupAreaHeight = this.getGroupAreaHeight();
46714701
const renderedHeight = toolbarHeight + actualTheadRow +
46724702
footerHeight + pagingHeight + groupAreaHeight +
@@ -4720,7 +4750,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
47204750
* @hidden @internal
47214751
*/
47224752
public get outerWidth() {
4723-
return this.hasVerticalScroll() ? this.calcWidth + this.scrollWidth : this.calcWidth;
4753+
return this.hasVerticalScroll() ? this.calcWidth + this.scrollSize : this.calcWidth;
47244754
}
47254755

47264756
/**
@@ -4814,7 +4844,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
48144844
}
48154845

48164846
if (this.hasVerticalScroll() && this.width !== null) {
4817-
width -= this.scrollWidth;
4847+
width -= this.scrollSize;
48184848
}
48194849
if ((Number.isFinite(width) || width === null) && width !== this.calcWidth) {
48204850
this.calcWidth = width;
@@ -4985,7 +5015,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
49855015
if (width === null) {
49865016
let currentWidth = this.calcWidth;
49875017
if (this.hasVerticalScroll()) {
4988-
currentWidth += this.scrollWidth;
5018+
currentWidth += this.scrollSize;
49895019
}
49905020
width = currentWidth + 'px';
49915021
this.resetCaches();
@@ -5027,7 +5057,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
50275057
this.calcWidth :
50285058
parseInt(this.width, 10) || parseInt(this.hostWidth, 10) || this.calcWidth;
50295059
if (this.hasVerticalScroll() && !this.isPercentWidth) {
5030-
width -= this.scrollWidth;
5060+
width -= this.scrollSize;
50315061
}
50325062
if (this.pinning.columns === ColumnPinningPosition.End) {
50335063
width -= this.featureColumnsWidth();
@@ -5429,15 +5459,17 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
54295459
let record = {};
54305460
const selectedData = [];
54315461
const activeEl = this.selectionService.activeElement;
5432-
5433-
const selectionMap = Array.from(this.selectionService.selection)
5434-
.filter((tuple) => tuple[0] < source.length);
5462+
const totalItems = (this as any).totalItemCount ?? 0;
5463+
const isRemote = totalItems && totalItems > this.dataView.length;
5464+
const selectionMap = isRemote ? Array.from(this.selectionService.selection) :
5465+
Array.from(this.selectionService.selection).filter((tuple) => tuple[0] < source.length);
54355466

54365467
if (this.cellSelection === GridSelectionMode.single && activeEl) {
54375468
selectionMap.push([activeEl.row, new Set<number>().add(activeEl.column)]);
54385469
}
54395470

5440-
for (const [row, set] of selectionMap) {
5471+
for (let [row, set] of selectionMap) {
5472+
row = isRemote ? row - this.virtualizationState.startIndex : row;
54415473
if (!source[row] || source[row].detailsData !== undefined) {
54425474
continue;
54435475
}

0 commit comments

Comments
 (0)