Skip to content

Commit 0f34280

Browse files
committed
fix(row-adding): splitting to two methods, fixing pinning #9675
1 parent 5c657cb commit 0f34280

File tree

6 files changed

+62
-21
lines changed

6 files changed

+62
-21
lines changed

Diff for: CHANGELOG.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
All notable changes for each version of this project will be documented in this file.
44

5-
6-
## 12.1.5
5+
## 12.1.6
76

87
### New Features
98
- `igxGrid`, `igxHierarchicalGrid`, `igxTreeGrid`
10-
- Added a public method that spawns the add row UI for an arbitrary record in the current data view. It accepts a rowID (PK when one is defined, index otherwise). You can also pass `null` to spawn the UI as the very first record. Please, note that the new record is still added at the end of the data view, after the end-user submits it.
9+
- Added two public methods that spawn the add row UI for an arbitrary record in the current data view. One that accepts a rowID to use as the row the UI spawns under and the other specifying the index at which to spawn it. Please, note that the new record is still added at the end of the data view, after the end-user submits it.
1110
```typescript
12-
this.grid.beginAddRow('ALFKI'); // spawns the add row UI under the row with PK 'ALFKI'
13-
this.grid.beginAddRow(null); // spawns the add row UI as the first record
11+
this.grid.beginAddRowById('ALFKI'); // spawns the add row UI under the row with PK 'ALFKI'
12+
this.grid.beginAddRowById('ALFKI', true); // spawns the add row UI to add a child for the row with PK 'ALFKI'
13+
this.grid.beginAddRowById(null); // spawns the add row UI as the first record
14+
this.grid.beginAddRowByIndex(10); // spawns the add row UI at index 10
15+
this.grid.beginAddRowByIndex(10, true); // spawns the add row UI to add a child for the row at index 9
16+
this.grid.beginAddRowByIndex(0); // spawns the add row UI as the first record
1417
```
1518

1619
## 12.1.3

Diff for: projects/igniteui-angular/src/lib/grids/common/crud.service.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ export class IgxRowAddCrudState extends IgxRowCrudState {
437437
*/
438438
public createAddRowParent(row: IgxRowDirective<IgxGridBaseDirective & GridType>, newRowAsChild?: boolean) {
439439
const rowIndex = row ? row.index : -1;
440-
const rowId = row ? row.rowID : (rowIndex >= 0 ? this.grid.rowList.last.rowID : null);
441-
440+
const rowId = row ? row.rowID : null;
442441
const isInPinnedArea = this.grid.isRecordPinnedByViewIndex(rowIndex);
443442
const pinIndex = this.grid.pinnedRecords.findIndex(x => x[this.primaryKey] === rowId);
444443
const unpinIndex = this.grid.getUnpinnedIndexById(rowId);

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

+40-9
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ import { IgxPaginatorComponent } from '../paginator/paginator.component';
156156
import { IgxGridHeaderRowComponent } from './headers/grid-header-row.component';
157157
import { IgxGridGroupByAreaComponent } from './grouping/grid-group-by-area.component';
158158
import { IgxFlatTransactionFactory, TRANSACTION_TYPE } from '../services/transaction/transaction-factory.service';
159+
import { SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION } from 'constants';
159160

160161
let FAKE_ROW_ID = -1;
161162
const DEFAULT_ITEMS_PER_PAGE = 15;
@@ -5967,42 +5968,48 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
59675968
}
59685969

59695970
/**
5970-
* Enters add mode for the specified rowID (primary key if one is defined, index otherwise)
5971+
* Enters add mode by spawning the UI under the specified row by rowID.
59715972
*
59725973
* @remarks
59735974
* If null is passed as rowID, the row adding UI is spawned as the first record in the data view
59745975
* @remarks
59755976
* Spawning the UI to add a child for a record only works if you provide a rowID
59765977
* @example
59775978
* ```typescript
5978-
* this.grid.beginAddRow('ALFKI');
5979-
* this.grid.beginAddRow(null);
5979+
* this.grid.beginAddRowById('ALFKI');
5980+
* this.grid.beginAddRowById('ALFKI', true);
5981+
* this.grid.beginAddRowById(null);
59805982
* ```
5981-
* @param rowID - The PK or index to spawn the add row UI for, or null to spawn it as the first record in the data view
5983+
* @param rowID - The rowID to spawn the add row UI for, or null to spawn it as the first record in the data view
59825984
* @param asChild - Whether the record should be added as a child. Only applicable to igxTreeGrid.
59835985
*/
5984-
public beginAddRow(rowID: any, asChild?: boolean): void {
5986+
public beginAddRowById(rowID: any, asChild?: boolean): void {
59855987
let index = rowID;
59865988
if (rowID == null) {
59875989
if (asChild) {
59885990
console.warn('The record cannot be added as a child to an unspecified record.');
59895991
return;
59905992
}
59915993
index = 0;
5992-
} else if (this.primaryKey !== null) {
5994+
} else {
59935995
// find the index of the record with that PK
59945996
index = this.gridAPI.get_rec_index_by_id(rowID);
59955997
rowID = index;
59965998
if (index === -1) {
5997-
console.warn('No row with the specified PK was found.');
5999+
console.warn('No row with the specified ID was found.');
59986000
return;
59996001
}
60006002
}
6003+
if (!this.dataView.length) {
6004+
this.beginAddRowForIndex(rowID, asChild);
6005+
return;
6006+
}
60016007
// check if the index is valid - won't support anything outside the data view
60026008
if (index >= 0 && index < this.dataView.length) {
60036009
// check if the index is in the view port
6004-
if (index < this.virtualizationState.startIndex ||
6005-
index >= this.virtualizationState.startIndex + this.virtualizationState.chunkSize) {
6010+
if ((index < this.virtualizationState.startIndex ||
6011+
index >= this.virtualizationState.startIndex + this.virtualizationState.chunkSize) &&
6012+
!this.isRecordPinnedByViewIndex(index)) {
60066013
this.verticalScrollContainer.chunkLoad
60076014
.pipe(first(), takeUntil(this.destroy$))
60086015
.subscribe(() => {
@@ -6018,6 +6025,30 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
60186025
}
60196026
}
60206027

6028+
/**
6029+
* Enters add mode by spawning the UI at the specified index.
6030+
*
6031+
* @remarks
6032+
* Accepted values for index are integers from 0 to this.grid.dataView.length
6033+
* @remarks
6034+
* When adding the row as a child, the parent row is the one at the previous index. You cannot add a child at index 0.
6035+
* @example
6036+
* ```typescript
6037+
* this.grid.beginAddRowByIndex(10);
6038+
* this.grid.beginAddRowByIndex(10, true);
6039+
* this.grid.beginAddRowByIndex(0);
6040+
* ```
6041+
* @param index - The index to spawn the UI at. Accepts integers from 0 to this.grid.dataView.length
6042+
* @param asChild - Whether the record should be added as a child. Only applicable to igxTreeGrid.
6043+
*/
6044+
public beginAddRowByIndex(index: number, asChild?: boolean): void {
6045+
if (index === 0) {
6046+
return this.beginAddRowById(null, asChild);
6047+
}
6048+
const record = this.dataView[index - 1];
6049+
return this.beginAddRowById(this.primaryKey ? record[this.primaryKey] : record, asChild);
6050+
}
6051+
60216052
protected beginAddRowForIndex(index: number, asChild: boolean = false) {
60226053
const row: IgxRowDirective<IgxGridBaseDirective & GridType> = index == null ?
60236054
null : this.rowList.find(r => r.index === index);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ describe('IgxGrid - Row Adding #grid', () => {
491491
await wait(DEBOUNCETIME);
492492
fixture.detectChanges();
493493

494-
grid.beginAddRow(null);
494+
grid.beginAddRowById(null);
495495

496496
await wait(DEBOUNCETIME);
497497
fixture.detectChanges();
@@ -503,7 +503,7 @@ describe('IgxGrid - Row Adding #grid', () => {
503503
await wait(DEBOUNCETIME);
504504
fixture.detectChanges();
505505

506-
grid.beginAddRow('FAMIA');
506+
grid.beginAddRowById('FAMIA');
507507

508508
await wait(DEBOUNCETIME);
509509
fixture.detectChanges();

Diff for: src/app/grid-add-row/grid-add-row.sample.html

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ <h1 igxCardHeaderTitle>Settings</h1>
4949
<label igxLabel for="index">Index</label>
5050
</igx-input-group>
5151
<button igxButton="raised" (click)="beginAddRowStart()">Add Row At Start</button>
52+
<igx-input-group>
53+
<input igxInput name="string" type="string" #stringInput value="CENTC"/>
54+
<label igxLabel for="string">PK</label>
55+
</igx-input-group>
56+
<button igxButton="raised" (click)="beginAddRowById(stringInput.value)">Add Row For ID</button>
5257
</igx-card-content>
5358
</igx-card>
5459
</div>

Diff for: src/app/grid-add-row/grid-add-row.sample.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,14 @@ export class GridAddRowSampleComponent implements OnInit {
7777

7878
public beginAddRowAtIndex(index: string) {
7979
const numeric = parseInt(index, 10);
80-
const PK = this.grid.dataView[numeric]['ID'];
81-
this.grid.beginAddRow(PK);
80+
this.grid.beginAddRowByIndex(numeric);
8281
}
8382

8483
public beginAddRowStart() {
85-
this.grid.beginAddRow(null);
84+
this.grid.beginAddRowById(null);
85+
}
86+
87+
public beginAddRowById(string: string) {
88+
this.grid.beginAddRowById(string);
8689
}
8790
}

0 commit comments

Comments
 (0)