Skip to content

Commit 6bc92f6

Browse files
Show number of defined columns as rowChangesCount for new row with batch editing (#12234)
* feat(grid): show correct number of changes for new row * chore(grid): add feature to CHANGELOG * refactor(grid): use private property
1 parent 76aa753 commit 6bc92f6

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ All notable changes for each version of this project will be documented in this
2222
- `dragIndicatorIconTemplate` - Gets/Sets the custom template used for row drag indicator.
2323
- `detailTemplate` - Gets/Sets the master-detail template.
2424

25+
- **Behavioral Change** - When adding new row in grid with enabled batch editing, `rowChangesCount` displays the number of the defined columns.
2526
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
2627
- **Behavioral Change** - When editing a row, `rowChangesCount` and `hiddenColumnsCount`would be displayed.
2728

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,6 +3219,9 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
32193219
Object.keys(obj).forEach(key => isObject(obj[key]) ? changes += f(obj[key]) : changes++);
32203220
return changes;
32213221
};
3222+
if (this.transactions.getState(this.crudService.row.id)?.type === TransactionType.ADD) {
3223+
return this._columns.filter(c => c.field).length;
3224+
}
32223225
const rowChanges = this.transactions.getAggregatedValue(this.crudService.row.id, false);
32233226
return rowChanges ? f(rowChanges) : 0;
32243227
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { configureTestSuite } from '../../test-utils/configure-suite';
55
import { DebugElement } from '@angular/core';
66
import { GridFunctions, GridSummaryFunctions } from '../../test-utils/grid-functions.spec';
77
import {
8-
IgxAddRowComponent, IgxGridRowEditingTransactionComponent
8+
IgxAddRowComponent, IgxGridRowEditingDefinedColumnsComponent, IgxGridRowEditingTransactionComponent
99
} from '../../test-utils/grid-samples.spec';
1010

1111
import { By } from '@angular/platform-browser';
@@ -45,7 +45,8 @@ describe('IgxGrid - Row Adding #grid', () => {
4545
IgxAddRowComponent,
4646
ColumnLayoutTestComponent,
4747
DefaultGridMasterDetailComponent,
48-
IgxGridRowEditingTransactionComponent
48+
IgxGridRowEditingTransactionComponent,
49+
IgxGridRowEditingDefinedColumnsComponent
4950
],
5051
imports: [
5152
NoopAnimationsModule,
@@ -1082,5 +1083,22 @@ describe('IgxGrid - Row Adding #grid', () => {
10821083
expect(states[0].type).toEqual(TransactionType.ADD);
10831084
expect(states[0].newValue['ProductName']).toEqual('aaa');
10841085
});
1086+
1087+
it('Should display number of defined columns for rowChangesCount', () => {
1088+
fixture = TestBed.createComponent(IgxGridRowEditingDefinedColumnsComponent);
1089+
fixture.detectChanges();
1090+
grid = fixture.componentInstance.grid;
1091+
1092+
const row = grid.rowList.first;
1093+
row.beginAddRow();
1094+
fixture.detectChanges();
1095+
endTransition();
1096+
1097+
let cellElem = grid.gridAPI.get_cell_by_index(10, 'ProductName');
1098+
UIInteractions.simulateDoubleClickAndSelectEvent(cellElem);
1099+
fixture.detectChanges();
1100+
1101+
expect(grid.rowChangesCount).toEqual(3);
1102+
});
10851103
});
10861104
});

projects/igniteui-angular/src/lib/test-utils/grid-samples.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,3 +2575,15 @@ export class ObjectCloneStrategy implements IDataCloneStrategy {
25752575
return clonedData;
25762576
}
25772577
}
2578+
2579+
@Component({
2580+
template: `
2581+
<igx-grid #grid [data]="data" [batchEditing]="true" [primaryKey]="'ProductID'" width="900px" height="900px" [rowEditable]="true" >
2582+
<igx-column field="ProductID" header="Product ID" width="150px" [hidden]="true"></igx-column>
2583+
<igx-column field="ProductName" header="Product Name" [dataType]="'string'" width="200px"></igx-column>
2584+
<igx-column field="InStock" header="In Stock" [dataType]="'boolean'" width="100px"></igx-column>
2585+
</igx-grid>`
2586+
})
2587+
export class IgxGridRowEditingDefinedColumnsComponent extends BasicGridComponent {
2588+
public data = SampleTestData.foodProductData();
2589+
}

0 commit comments

Comments
 (0)