Skip to content

Commit b4ee40b

Browse files
authored
Merge branch '9.1.x' into mvenkov/call_notifychanges_correctly
2 parents 42b51eb + 113f9da commit b4ee40b

31 files changed

+343
-79
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/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: 46 additions & 14 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
@@ -2489,6 +2504,14 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
24892504
* @hidden
24902505
*/
24912506
protected _paging = false;
2507+
/**
2508+
* @hidden
2509+
*/
2510+
protected _pagingMode = GridPagingMode.local;
2511+
/**
2512+
* @hidden @internal
2513+
*/
2514+
public _totalRecords = -1;
24922515
/**
24932516
* @hidden
24942517
*/
@@ -3614,7 +3637,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
36143637
if (this.pagingState) {
36153638
return this.pagingState.metadata.countPages;
36163639
}
3617-
return -1;
3640+
return this._totalRecords >= 0 ? Math.ceil(this._totalRecords / this.perPage) : -1;
36183641
}
36193642

36203643
/**
@@ -3663,9 +3686,16 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
36633686
* const totalRecords = this.grid.totalRecords;
36643687
* ```
36653688
*/
3689+
@Input()
36663690
get totalRecords(): number {
3667-
if (this.pagingState) {
3668-
return this.pagingState.metadata.countRecords;
3691+
return this._totalRecords >= 0 ? this._totalRecords : this.pagingState?.metadata.countRecords;
3692+
}
3693+
3694+
set totalRecords(total: number) {
3695+
if (total >= 0) {
3696+
this._totalRecords = total;
3697+
this._pipeTrigger++;
3698+
this.notifyChanges();
36693699
}
36703700
}
36713701

@@ -4713,7 +4743,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
47134743
* @hidden @internal
47144744
*/
47154745
public get outerWidth() {
4716-
return this.hasVerticalScroll() ? this.calcWidth + this.scrollWidth : this.calcWidth;
4746+
return this.hasVerticalScroll() ? this.calcWidth + this.scrollSize : this.calcWidth;
47174747
}
47184748

47194749
/**
@@ -4807,7 +4837,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
48074837
}
48084838

48094839
if (this.hasVerticalScroll() && this.width !== null) {
4810-
width -= this.scrollWidth;
4840+
width -= this.scrollSize;
48114841
}
48124842
if ((Number.isFinite(width) || width === null) && width !== this.calcWidth) {
48134843
this.calcWidth = width;
@@ -4978,7 +5008,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
49785008
if (width === null) {
49795009
let currentWidth = this.calcWidth;
49805010
if (this.hasVerticalScroll()) {
4981-
currentWidth += this.scrollWidth;
5011+
currentWidth += this.scrollSize;
49825012
}
49835013
width = currentWidth + 'px';
49845014
this.resetCaches();
@@ -5020,7 +5050,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
50205050
this.calcWidth :
50215051
parseInt(this.width, 10) || parseInt(this.hostWidth, 10) || this.calcWidth;
50225052
if (this.hasVerticalScroll() && !this.isPercentWidth) {
5023-
width -= this.scrollWidth;
5053+
width -= this.scrollSize;
50245054
}
50255055
if (this.pinning.columns === ColumnPinningPosition.End) {
50265056
width -= this.featureColumnsWidth();
@@ -5422,15 +5452,17 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
54225452
let record = {};
54235453
const selectedData = [];
54245454
const activeEl = this.selectionService.activeElement;
5425-
5426-
const selectionMap = Array.from(this.selectionService.selection)
5427-
.filter((tuple) => tuple[0] < source.length);
5455+
const totalItems = (this as any).totalItemCount ?? 0;
5456+
const isRemote = totalItems && totalItems > this.dataView.length;
5457+
const selectionMap = isRemote ? Array.from(this.selectionService.selection) :
5458+
Array.from(this.selectionService.selection).filter((tuple) => tuple[0] < source.length);
54285459

54295460
if (this.cellSelection === GridSelectionMode.single && activeEl) {
54305461
selectionMap.push([activeEl.row, new Set<number>().add(activeEl.column)]);
54315462
}
54325463

5433-
for (const [row, set] of selectionMap) {
5464+
for (let [row, set] of selectionMap) {
5465+
row = isRemote ? row - this.virtualizationState.startIndex : row;
54345466
if (!source[row] || source[row].detailsData !== undefined) {
54355467
continue;
54365468
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe('IgxGrid - Cell component #grid', () => {
201201
// Calculate where the end of the cell is. Relative left position should equal the grid calculated width
202202
expect(lastCell.nativeElement.getBoundingClientRect().left +
203203
lastCell.nativeElement.offsetWidth +
204-
grid.scrollWidth).toEqual(parseInt(grid.width, 10));
204+
grid.scrollSize).toEqual(parseInt(grid.width, 10));
205205
}));
206206

207207
it('should not reduce the width of last pinned cell when there is vertical scroll.', () => {

projects/igniteui-angular/src/lib/grids/grid/column-group.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ describe('IgxGrid - multi-column headers #grid', () => {
191191
tick();
192192

193193
const locationColGroup = getColGroup(grid, 'Location');
194-
expect(parseInt(locationColGroup.width, 10) + grid.scrollWidth).toBe(parseInt(componentInstance.gridWrapperWidthPx, 10));
194+
expect(parseInt(locationColGroup.width, 10) + grid.scrollSize).toBe(parseInt(componentInstance.gridWrapperWidthPx, 10));
195195
const cityColumn = grid.getColumnByName('City');
196-
expect(parseInt(cityColumn.width, 10) + grid.scrollWidth).toBe(parseInt(componentInstance.gridWrapperWidthPx, 10));
196+
expect(parseInt(cityColumn.width, 10) + grid.scrollSize).toBe(parseInt(componentInstance.gridWrapperWidthPx, 10));
197197
}));
198198

199199
it('Width should be correct. Column group with column. Width in px.', fakeAsync(() => {
@@ -208,9 +208,9 @@ describe('IgxGrid - multi-column headers #grid', () => {
208208
fixture.detectChanges();
209209

210210
const locationColGroup = getColGroup(grid, 'Location');
211-
expect(parseInt(locationColGroup.width, 10) + grid.scrollWidth).toBe(gridWidthPx);
211+
expect(parseInt(locationColGroup.width, 10) + grid.scrollSize).toBe(gridWidthPx);
212212
const cityColumn = grid.getColumnByName('City');
213-
expect(parseInt(cityColumn.width, 10) + grid.scrollWidth).toBe(gridWidthPx);
213+
expect(parseInt(cityColumn.width, 10) + grid.scrollSize).toBe(gridWidthPx);
214214
}));
215215

216216
it('Width should be correct. Column group with column. Width in percent.', fakeAsync(() => {
@@ -226,7 +226,7 @@ describe('IgxGrid - multi-column headers #grid', () => {
226226

227227
const locationColGroup = getColGroup(grid, 'Location');
228228
const gridWidthInPx = ((parseInt(gridWidth, 10) / 100) *
229-
parseInt(componentInstance.gridWrapperWidthPx, 10) - grid.scrollWidth) + 'px';
229+
parseInt(componentInstance.gridWrapperWidthPx, 10) - grid.scrollSize) + 'px';
230230
expect(locationColGroup.width).toBe(gridWidthInPx);
231231
const cityColumn = grid.getColumnByName('City');
232232
expect(cityColumn.width).toBe(gridWidthInPx);

0 commit comments

Comments
 (0)