Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ngrid): filler should update when collection change refactor(ngrid): add "onDestroy" table event fix(ngrid): clear context when datasource change fix(ngrid): update paginator when datasource change fix(ngrid/detail-row): populate row in detail toggle event feat(ngrid): bind / unbind table to datasource (external)
- Loading branch information
1 parent
6a41cd0
commit c06bc17
Showing
26 changed files
with
3,106 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"version": "independent", | ||
"npmClient": "yarn", | ||
"command": { | ||
"publish": { | ||
"ignoreChanges": ["ignored-file", "*.md"], | ||
"conventionalCommits": true, | ||
"message": "chore(release): release" | ||
}, | ||
"version": { | ||
"push": false | ||
} | ||
}, | ||
"packages": [ | ||
"libs/utils", | ||
"libs/ngrid", | ||
"libs/ngrid-material" | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
libs/apps/ngrid/features/src/lib/modules/table-demo/filler/filler.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<docsi-bt-source-code-ref file="./filler.component.ts" [section]='["ex-1"]'></docsi-bt-source-code-ref> | ||
<docsi-bt-source-code-ref file="./filler.component.md" lang="html" [section]='["ex-1"]'></docsi-bt-source-code-ref> | ||
<docsi-bt-compile-markdown src="./filler.component.md"></docsi-bt-compile-markdown> |
38 changes: 38 additions & 0 deletions
38
libs/apps/ngrid/features/src/lib/modules/table-demo/filler/filler.component.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Grid Filler | ||
|
||
The table's background is transparent, when the total height of the rows is lower then the height available this is visible. | ||
|
||
The filler is a `<div>` that is added at the bottom of the grid and takes up | ||
the height left. | ||
|
||
You can customize it's background through the CSS class `pbl-ngrid-space-fill` | ||
|
||
I> You can also solve this by assigning a background color to the table but this is not always suitable. | ||
|
||
In the following example the table is rendered inside a div container that has a `lightgreen` background color. | ||
|
||
<docsi-mat-example-with-source title="Filler" contentClass="mat-elevation-z7" [query]="[{section: 'ex-1'}]"> | ||
<!--@pebula-example:ex-1--> | ||
<div class="filler-table-container"> | ||
<pbl-ngrid blockUi vScrollAuto [dataSource]="dsVScrollAuto" [columns]="columns"> | ||
<pbl-demo-action-row filter ></pbl-demo-action-row> | ||
</pbl-ngrid> | ||
</div> | ||
<!--@pebula-example:ex-1--> | ||
</docsi-mat-example-with-source> | ||
|
||
#### The same thing, now with fixed mode virtual scroll: | ||
|
||
<div class="filler-table-container"> | ||
<pbl-ngrid blockUi vScrollFixed [dataSource]="dsVScrollFixed" [columns]="columns"> | ||
<pbl-demo-action-row filter " ></pbl-demo-action-row> | ||
</pbl-ngrid> | ||
</div> | ||
|
||
W> Currently, the filler is not supported when virtual scroll is disabled (`vScrollNone`) | ||
|
||
<div class="filler-table-container"> | ||
<pbl-ngrid blockUi vScrollNone [dataSource]="dsVScrollNone" [columns]="columns"> | ||
<pbl-demo-action-row filter " ></pbl-demo-action-row> | ||
</pbl-ngrid> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
libs/apps/ngrid/features/src/lib/modules/table-demo/filler/filler.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.filler-table-container { | ||
padding: 16px; | ||
height: 400px; | ||
background: lightgreen; | ||
|
||
pbl-ngrid { | ||
height: 100%; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
libs/apps/ngrid/features/src/lib/modules/table-demo/filler/filler.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* @pebula-example:ex-1 */ | ||
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core'; | ||
import { createDS, columnFactory } from '@pebula/ngrid'; | ||
|
||
import { Person, DemoDataSource } from '@pebula/apps/ngrid/shared'; | ||
|
||
const COLUMNS = columnFactory() | ||
.table( | ||
{ prop: 'id', sort: true, width: '40px' }, | ||
{ prop: 'name', sort: true }, | ||
{ prop: 'gender', width: '50px' }, | ||
{ prop: 'birthdate', type: 'date' }, | ||
{ prop: 'email', minWidth: 250, width: '250px' }, | ||
{ prop: 'language', headerType: 'language' }, | ||
) | ||
.build(); | ||
|
||
@Component({ | ||
selector: 'pbl-filler-grid-example-component', | ||
templateUrl: './filler.component.html', | ||
styleUrls: ['./filler.component.scss'], | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class FillerGridExampleComponent { | ||
|
||
columns = COLUMNS; | ||
dsVScrollAuto = createDS<Person>().onTrigger( () => this.datasource.getPeople(0, 3) ).create(); | ||
dsVScrollFixed = createDS<Person>().onTrigger( () => this.datasource.getPeople(0, 3) ).create(); | ||
dsVScrollNone = createDS<Person>().onTrigger( () => this.datasource.getPeople(0, 3) ).create(); | ||
|
||
constructor(private datasource: DemoDataSource) { } | ||
} | ||
/* @pebula-example:ex-1 */ |
3 changes: 3 additions & 0 deletions
3
libs/apps/ngrid/features/src/lib/modules/table-demo/reuse/reuse.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<docsi-bt-source-code-ref file="./reuse.component.ts" [section]='["ex-1"]'></docsi-bt-source-code-ref> | ||
<docsi-bt-source-code-ref file="./reuse.component.md" lang="html" [section]='["ex-1"]'></docsi-bt-source-code-ref> | ||
<docsi-bt-compile-markdown src="./reuse.component.md"></docsi-bt-compile-markdown> |
49 changes: 49 additions & 0 deletions
49
libs/apps/ngrid/features/src/lib/modules/table-demo/reuse/reuse.component.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Table Re-Use | ||
|
||
Reusing of a table refers to changing the model that the table represents. | ||
|
||
Looking at the following column factory the model is quite clear: | ||
|
||
```typescript | ||
columnFactory() | ||
.table( | ||
{ prop: 'id' }, | ||
{ prop: 'name' }, | ||
{ prop: 'email' }, | ||
) | ||
.build(); | ||
``` | ||
|
||
For this column definition set, the table expects a similar collection of objects returned from the data source. | ||
|
||
The datasource is dynamic, returning values per demand. | ||
|
||
```typescript | ||
createDS<Person>() | ||
.onTrigger( (event) => [ { id: 1, name: 'John', email: 'N/A' }] ) | ||
.create(); | ||
``` | ||
|
||
Now, if we want to apply a different model on the table? We will have to change the column definition set as well at the datasource. | ||
|
||
In the following example the table can toggle between showing a **Person** model or a **Seller** model. | ||
|
||
<docsi-mat-example-with-source title="Re-Use" contentClass="table-height-300 mat-elevation-z7" [query]="[{section: 'ex-1'}]"> | ||
<!--@pebula-example:ex-1--> | ||
<pbl-ngrid blockUi usePagination [dataSource]="dynamicColumnsDs" [columns]="dynamicColumns"> | ||
<pbl-ngrid-paginator *pblNgridPaginatorRef="let table" | ||
[table]="table" | ||
[paginator]="table.ds.paginator"></pbl-ngrid-paginator> | ||
</pbl-ngrid> | ||
<!--@pebula-example:ex-1--> | ||
</docsi-mat-example-with-source> | ||
|
||
<button (click)="toggleViewMode()">{{ viewMode }}</button> | ||
|
||
When we toggle, notice that we swap the entire datasource. We could have implemented the logic inside the `onTrigger` handler and keep a single datasource but it will not work. | ||
|
||
When we swap a datasource the table will cleanup the context and all column related data and rebuilt it preventing ghost context living in the cache. | ||
|
||
I> When a table gets destroyed (`ngOnDestroy`) the datasource attached to it (if attached) is disconnected and automatically disposed. This has 1 exception, the `keepAlive` configuration was enabled on the datasource. | ||
|
||
W> When you swap the datasource it will also cause the previous datasource to disconnect, if `keepAlive` is `false` it will also dispose itself. |
Empty file.
81 changes: 81 additions & 0 deletions
81
libs/apps/ngrid/features/src/lib/modules/table-demo/reuse/reuse.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* @pebula-example:ex-1 */ | ||
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core'; | ||
import { createDS, columnFactory } from '@pebula/ngrid'; | ||
|
||
import { Seller, Person, DemoDataSource } from '@pebula/apps/ngrid/shared'; | ||
|
||
function buildColumns(mode: 'person' | 'seller') { | ||
if (mode === 'person') { | ||
return columnFactory() | ||
.table( | ||
{ prop: 'id', sort: true, width: '40px' }, | ||
{ prop: 'name', sort: true }, | ||
{ prop: 'gender', width: '50px' }, | ||
{ prop: 'birthdate', type: 'date' }, | ||
{ prop: 'bio' }, | ||
{ prop: 'email', minWidth: 250, width: '250px' }, | ||
{ prop: 'language', headerType: 'language' }, | ||
) | ||
.build(); | ||
} else { | ||
return columnFactory() | ||
.table( | ||
{ prop: 'id', sort: true, width: '40px', wontBudge: true }, | ||
{ prop: 'name', sort: true }, | ||
{ prop: 'email', minWidth: 250, width: '150px' }, | ||
{ prop: 'address' }, | ||
{ prop: 'rating', type: 'starRatings', width: '120px' } | ||
) | ||
.build(); | ||
} | ||
} | ||
|
||
function createSource(mode: 'person' | 'seller', datasource: DemoDataSource) { | ||
if (mode === 'person') { | ||
return createDS<Person>().onTrigger(() => { | ||
return datasource.getPeople(1000, 15); | ||
}).create(); | ||
} else { | ||
return createDS<Seller>().onTrigger(() => { | ||
return datasource.getSellers(1000, 15) | ||
}).create(); | ||
} | ||
}; | ||
|
||
@Component({ | ||
selector: 'pbl-reuse-grid-example-component', | ||
templateUrl: './reuse.component.html', | ||
styleUrls: ['./reuse.component.scss'], | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ReuseGridExampleComponent { | ||
|
||
|
||
dynamicColumns; | ||
dynamicColumnsDs = createDS<Person | Seller>().onTrigger(() => { | ||
if (this.viewMode === 'person') { | ||
return this.datasource.getPeople(1000, 15); | ||
} else { | ||
return this.datasource.getSellers(1000, 15) | ||
} | ||
}).create(); | ||
|
||
columns = buildColumns('person'); | ||
ds2 = createDS<Person>().onTrigger( () => this.datasource.getPeople(0, 15) ).create(); | ||
ds3 = createDS<Person>().onTrigger( () => this.datasource.getPeople(0, 15) ).create(); | ||
|
||
viewMode: 'person' | 'seller' = 'person'; | ||
|
||
constructor(private datasource: DemoDataSource) { | ||
this.toggleViewMode(); | ||
} | ||
|
||
toggleViewMode(): void { | ||
this.viewMode = this.viewMode === 'person' ? 'seller' : 'person'; | ||
this.dynamicColumnsDs = createSource(this.viewMode, this.datasource); | ||
this.dynamicColumns = buildColumns(this.viewMode); | ||
this.dynamicColumnsDs.refresh(); | ||
} | ||
} | ||
/* @pebula-example:ex-1 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.