Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion projects/igniteui-angular/grids/core/src/watch-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function WatchChanges(): PropertyDecorator {
const oldValue = this[key];
if (val !== oldValue || (typeof val === 'object' && val === oldValue)) {
originalSetter.call(this, val);
if (this.ngOnChanges && !init) {
// Explicitly check whether the decorator is called during initialization
if (this.ngOnChanges && init !== undefined && !init) {
// in case wacthed prop changes trigger ngOnChanges manually
const changes: SimpleChanges = {
[key]: new SimpleChange(oldValue, val, false)
Expand Down
25 changes: 19 additions & 6 deletions projects/igniteui-angular/grids/grid/src/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import {
ViewContainerRef,
DOCUMENT,
inject,
InjectionToken
InjectionToken,
SimpleChanges,
OnChanges
} from '@angular/core';
import {
areEqualArrays,
Expand Down Expand Up @@ -108,7 +110,7 @@ import { IgxGridRowComponent } from './grid-row.component';
import { IgxPaginatorToken, type IgxPaginatorComponent } from 'igniteui-angular/paginator';
import { IgxSnackbarComponent } from 'igniteui-angular/snackbar';
import { CharSeparatedValueData, DropPosition, FilterMode, getUUID, GridCellMergeMode, GridKeydownTargetType, GridPagingMode, GridSelectionMode, GridSelectionRange, GridServiceType, GridSummaryPosition, GridType, GridValidationTrigger, IActiveNode, IActiveNodeChangeEventArgs, ICellPosition, IClipboardOptions, IColumnMovingEndEventArgs, IColumnMovingEventArgs, IColumnMovingStartEventArgs, IColumnResizeEventArgs, IColumnsAutoGeneratedEventArgs, IColumnSelectionEventArgs, IColumnVisibilityChangedEventArgs, IColumnVisibilityChangingEventArgs, IFilteringEventArgs, IGridCellEventArgs, IGridClipboardEvent, IGridContextMenuEventArgs, IGridEditDoneEventArgs, IGridEditEventArgs, IGridFormGroupCreatedEventArgs, IGridKeydownEventArgs, IGridRowEventArgs, IGridScrollEventArgs, IGridToolbarExportEventArgs, IGridValidationStatusEventArgs, IGX_GRID_SERVICE_BASE, IgxAdvancedFilteringDialogComponent, IgxCell, IgxColumnComponent, IgxColumnGroupComponent, IgxColumnResizingService, IgxDragIndicatorIconDirective, IgxEditRow, IgxExcelStyleHeaderIconDirective, IgxExcelStyleLoadingValuesTemplateDirective, IgxFilteringService, IgxGridBodyDirective, IgxGridCellComponent, IgxGridColumnResizerComponent, IgxGridEmptyTemplateContext, IgxGridEmptyTemplateDirective, IgxGridExcelStyleFilteringComponent, IgxGridFilteringCellComponent, IgxGridFilteringRowComponent, IgxGridGroupByAreaComponent, IgxGridHeaderComponent, IgxGridHeaderGroupComponent, IgxGridHeaderRowComponent, IgxGridHeaderTemplateContext, IgxGridLoadingTemplateDirective, IgxGridNavigationService, IgxGridRowDragGhostContext, IgxGridRowEditActionsTemplateContext, IgxGridRowEditTemplateContext, IgxGridRowEditTextTemplateContext, IgxGridRowTemplateContext, IgxGridSelectionService, IgxGridSummaryService, IgxGridTemplateContext, IgxGridToolbarComponent, IgxGridTransaction, IgxGridValidationService, IgxHeaderCollapsedIndicatorDirective, IgxHeaderExpandedIndicatorDirective, IgxHeadSelectorDirective, IgxHeadSelectorTemplateContext, IgxRowAddTextDirective, IgxRowCollapsedIndicatorDirective, IgxRowDirective, IgxRowDragGhostDirective, IgxRowEditActionsDirective, IgxRowEditTabStopDirective, IgxRowEditTemplateDirective, IgxRowEditTextDirective, IgxRowExpandedIndicatorDirective, IgxRowSelectorDirective, IgxRowSelectorTemplateContext, IgxSortAscendingHeaderIconDirective, IgxSortDescendingHeaderIconDirective, IgxSortHeaderIconDirective, IgxSummaryRowComponent, IgxToolbarToken, IPinColumnCancellableEventArgs, IPinColumnEventArgs, IPinningConfig, IPinRowEventArgs, IRowDataCancelableEventArgs, IRowDataEventArgs, IRowDragEndEventArgs, IRowDragStartEventArgs, IRowSelectionEventArgs, IRowToggleEventArgs, ISearchInfo, ISizeInfo, ISortingEventArgs, RowEditPositionStrategy, RowPinningPosition, RowType, WatchChanges } from 'igniteui-angular/grids/core';
import { getCurrentI18n, getNumberFormatter, IResourceChangeEventArgs, } from 'igniteui-i18n-core';
import { getCurrentI18n, getNumberFormatter, IResourceChangeEventArgs, } from 'igniteui-i18n-core';
import { I18N_FORMATTER } from 'igniteui-angular/core';

/**
Expand Down Expand Up @@ -143,7 +145,7 @@ const MIN_ROW_EDITING_COUNT_THRESHOLD = 2;
wcSkipComponentSuffix */
@Directive()
export abstract class IgxGridBaseDirective implements GridType,
OnInit, DoCheck, OnDestroy, AfterContentInit, AfterViewInit {
OnInit, DoCheck, OnDestroy, AfterContentInit, AfterViewInit, OnChanges {

/* blazorSuppress */
public readonly validation = inject(IgxGridValidationService);
Expand Down Expand Up @@ -197,6 +199,7 @@ export abstract class IgxGridBaseDirective implements GridType,
* <igx-grid [data]="Data" [autoGenerate]="true"></igx-grid>
* ```
*/
@WatchChanges()
@Input({ transform: booleanAttribute })
public autoGenerate = false;

Expand Down Expand Up @@ -4047,8 +4050,8 @@ export abstract class IgxGridBaseDirective implements GridType,
const activeRow = this.navigation.activeNode?.row;

const selectedCellIndexes = this.selectionService.selection
? Array.from(this.selectionService.selection.keys())
: [];
? Array.from(this.selectionService.selection.keys())
: [];
this._activeRowIndexes = [activeRow, ...selectedCellIndexes];
return this._activeRowIndexes;
}
Expand Down Expand Up @@ -4270,6 +4273,16 @@ export abstract class IgxGridBaseDirective implements GridType,
}
}

/**
* @hidden @internal
*/
public ngOnChanges(changes: SimpleChanges) {
if (!changes.autoGenerate?.firstChange && changes.autoGenerate?.currentValue && this.data?.length > 0 && this.columnList?.length === 0) {
// Make sure to setup columns only after the grid is initialized and autoGenerate is changed
this.setupColumns();
}
}

/**
* @hidden
* @internal
Expand Down Expand Up @@ -6776,7 +6789,7 @@ export abstract class IgxGridBaseDirective implements GridType,
} else if (this.width !== null) {
this._columnWidth = Math.max(parseFloat(possibleWidth), this.minColumnWidth) + 'px'
} else {
this._columnWidth = this.minColumnWidth + 'px';
this._columnWidth = this.minColumnWidth + 'px';
}
}
this._columns.forEach((column: IgxColumnComponent) => {
Expand Down
19 changes: 19 additions & 0 deletions projects/igniteui-angular/grids/grid/src/grid.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ describe('IgxGrid Component Tests #grid', () => {
expect(fix.componentInstance.columnEventCount).toEqual(4);
});

it('should initialize a grid with data and columns if autoGenerate is set after the data', () => {
const fix = TestBed.createComponent(IgxGridTestComponent);
fix.componentInstance.data = [
{ Number: 1, String: '1', Boolean: true, Date: new Date(Date.now()) }
];
fix.componentInstance.columns = [];
fix.detectChanges();

const grid = fix.componentInstance.grid;

expect(grid.columns.length).toBe(0);

fix.componentInstance.autoGenerate = true;
fix.detectChanges();

expect(grid.columns.length).toBe(4);
expect(grid.rowList.length).toBe(1);
});

it('should initialize a grid and change column properties during initialization', () => {
const fix = TestBed.createComponent(IgxGridTestComponent);
fix.componentInstance.columns = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export class IgxRowIslandComponent extends IgxHierarchicalGridBaseDirective
/**
* @hidden
*/
public ngOnChanges(changes) {
public override ngOnChanges(changes) {
this.layoutChange.emit(changes);
if (!this.isInit) {
this.initialChanges.push(changes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
/**
* @hidden @internal
*/
public ngOnChanges(changes: SimpleChanges) {
public override ngOnChanges(changes: SimpleChanges) {
if (changes.superCompactMode && !changes.superCompactMode.isFirstChange()) {
this._shouldUpdateSizes = true;
resizeObservable(this.verticalScrollContainer.displayContainer).pipe(take(1), takeUntil(this.destroy$)).subscribe(() => this.resizeNotify.next());
Expand Down
Loading