Skip to content

Commit

Permalink
perf(ngrid): use internal row context
Browse files Browse the repository at this point in the history
With this commit, the context provided to rows is now an internal ngrid context class and not the context provided by CdkTable.
This allow better control over the context but comes with a big refactor removing large chunks of code used to sync between the previous added context and the CdkContext.
  • Loading branch information
shlomiassaf committed Dec 3, 2020
1 parent 211643e commit f7f8367
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
[ngridCellClass]="value < 0 ? col.type.data.pbl : col.type.data.pos">{{ value | currency:col.type.data.meta.currency(row):'symbol':col.type.data.format }}</div>
<div *pblNgridCellTypeDef="'flagAndCountry'; col as col; row as row">{{ col.type.data.flagAndCountry(row) }}</div>

<pbl-ngrid-row in *pblNgridInfiniteVirtualRowDef="let row; gridInstance as gridInstance" class="pbl-ngrid-infinite-virtual-row" [grid]="gridInstance" [infiniteRow]="row">
<pbl-ngrid-row in *pblNgridInfiniteVirtualRowDef="let row; grid as grid" class="pbl-ngrid-infinite-virtual-row" [grid]="grid" [infiniteRow]="row">
<mat-spinner diameter="24"></mat-spinner>
</pbl-ngrid-row>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- This should be declared in a top-level component (e.g. app root) -->
<pbl-ngrid-row *pblNgridDetailRowParentRef="let row; gridInstance as gridInstance" [grid]="gridInstance" [detailRow]="row" matRipple></pbl-ngrid-row>

<pbl-ngrid blockUi [dataSource]="ds" [columns]="columns" vScrollNone
detailRow (toggleChange)="onToggleChange($event)">
Expand All @@ -9,6 +8,8 @@ <h1>Detail Row</h1>
<pre>{{row | json}}</pre>
</div>
</div>

<pbl-ngrid-row *pblNgridDetailRowParentRef="let row; grid as grid" [grid]="grid" [detailRow]="row" matRipple></pbl-ngrid-row>
</pbl-ngrid>

<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<pbl-ngrid [dataSource]="ds" [columns]="columns">
<mat-progress-bar *ngIf="ds.adapter.virtualRowsLoading | async" mode="indeterminate"></mat-progress-bar>

<pbl-ngrid-row in *pblNgridInfiniteVirtualRowDef="let row; gridInstance as gridInstance" class="pbl-ngrid-infinite-virtual-row" [grid]="gridInstance" [row]="row">
<pbl-ngrid-row in *pblNgridInfiniteVirtualRowDef="let row; grid as grid" class="pbl-ngrid-infinite-virtual-row" [grid]="grid" [row]="row">
</pbl-ngrid-row>

</pbl-ngrid>
2 changes: 1 addition & 1 deletion libs/ngrid/detail-row/src/lib/detail-row/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ export class PblNgridDetailRowParentRefDirective<T> extends PblNgridRowDef<T> im
*/
@Component({
selector: 'pbl-ngrid-default-detail-row-parent',
template: `<pbl-ngrid-row *pblNgridDetailRowParentRef="let row; gridInstance as gridInstance" [grid]="gridInstance" [detailRow]="row"></pbl-ngrid-row>`,
template: `<pbl-ngrid-row *pblNgridDetailRowParentRef="let row; grid as grid" [grid]="grid" [detailRow]="row"></pbl-ngrid-row>`,
})
export class PblNgridDefaultDetailRowParentComponent { }
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<pbl-ngrid-row in *pblNgridInfiniteVirtualRowDef="let row; gridInstance as gridInstance" class="pbl-ngrid-infinite-virtual-row" [grid]="gridInstance" [infiniteRow]="row">
<pbl-ngrid-row in *pblNgridInfiniteVirtualRowDef="let row; grid as grid" class="pbl-ngrid-infinite-virtual-row" [grid]="grid" [infiniteRow]="row">
...Loading
</pbl-ngrid-row>
5 changes: 2 additions & 3 deletions libs/ngrid/src/lib/grid/cell/cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export class PblNgridCellComponent extends PblNgridBaseCell implements DoCheck {
}
}

setContext(context: RowContext<any>) {
this.__rowCtx = context;
setContext(context: PblRowContext<any>) {
this._rowCtx = context;
}

setColumn(column: PblColumn) {
Expand Down Expand Up @@ -84,7 +84,6 @@ export class PblNgridCellComponent extends PblNgridBaseCell implements DoCheck {
}

ngDoCheck(): void {
this._rowCtx = this.__rowCtx?.pblRowContext as any;
if (this._rowCtx) {
const cellContext = this.cellCtx = this._rowCtx.cell(this.colIndex);

Expand Down
Loading

0 comments on commit f7f8367

Please sign in to comment.