Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit c5e4837

Browse files
authored
feat(filter): add collectionLazy callback to Column Filter (#1344)
1 parent 25e86eb commit c5e4837

11 files changed

Lines changed: 202 additions & 140 deletions

File tree

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
The [`docs`](https://github.com/ghiscoding/aurelia-slickgrid/tree/master/docs) folder of Aurelia-Slickgrid is the one-stop-shop for all project related documentation.
44

5-
Feel free to contribution documentation fixes by editing any of the markdown files in the [`docs`](https://github.com/ghiscoding/aurelia-slickgrid/tree/master/docs) folder.
5+
Feel free to contribute documentation fixes by editing any of the markdown files located in the [`docs`](https://github.com/ghiscoding/aurelia-slickgrid/tree/master/docs) folder.

docs/column-functionalities/editors/select-dropdown-editor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ this.columnDefinitions = [
173173
```
174174
175175
### Collection Watch
176-
Sometime you wish that whenever you change your filter collection, you'd like the filter to be updated, it won't do that by default but you could use `enableCollectionWatch` for that purpose to add collection observers and re-render the Filter DOM element whenever the collection changes. Also note that using `collectionAsync` will automatically watch for changes, so there's no need to enable this flag for that particular use case.
176+
Sometime you wish that whenever you make a change in your filter collection, you'd like the filter to be updated but it won't do that by default. You could use `enableCollectionWatch` for that purpose which will add a collection observers and re-render the Filter DOM element whenever the collection changes. Also note that using `collectionAsync` will automatically watch for changes, so there's no need to enable this flag for that particular use case.
177177
178178
```typescript
179179
this.columnDefinitions = [

docs/column-functionalities/filters/select-filter.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
- [How to add Translation](#how-to-add-translation)
77
- [How to filter empty values](#how-to-filter-empty-values)
88
- Collection Options
9-
- [Add Blank Entry](#collection-add-blank-entry)
10-
- [Add Custom Entry at Beginning/End of Collection](#collection-add-custom-entry-at-the-beginningend-of-the-collection)
11-
- [Custom Structure](#custom-structure-keylabel-pair)
12-
- [Custom Structure with Translation](#custom-structure-with-translation)
13-
- [Collection filterBy/sortBy](#collection-filterbysortby)
14-
- [Collection Label Prefix/Suffix](#collection-label-prefixsuffix)
15-
- [Collection Label Render HTML](#collection-label-render-html)
16-
- [Collection Async Load](#collection-async-load)
17-
- [Collection Watch](#collection-watch)
9+
- [Add Blank Entry](#collection-add-blank-entry)
10+
- [Add Custom Entry at Beginning/End of Collection](#collection-add-custom-entry-at-the-beginningend-of-the-collection)
11+
- [Custom Structure](#custom-structure-keylabel-pair)
12+
- [Custom Structure with Translation](#custom-structure-with-translation)
13+
- [Collection filterBy/sortBy](#collection-filterbysortby)
14+
- [Collection Label Prefix/Suffix](#collection-label-prefixsuffix)
15+
- [Collection Label Render HTML](#collection-label-render-html)
16+
- [Collection Async Load](#collection-async-load)
17+
- [Collection Lazy Load](#collection-lazy-load)
18+
- [Collection Watch](#collection-watch)
1819
- [`multiple-select.js` Options](#multiple-selectjs-options)
1920
- [Filter Options (`MultipleSelectOption` interface)](#filter-options-multipleselectoption-interface)
2021
- [Display shorter selected label text](#display-shorter-selected-label-text)
@@ -539,6 +540,24 @@ For example
539540
}
540541
```
541542

543+
### Collection Lazy Load
544+
In some cases, you might have a grid with a lot of columns and loading the collection only after opening the select dropdown (or never in some cases) might help speeding up the initial grid loading. So for that use case, defining a `collectionLazy` callback can help.
545+
546+
#### Load the collection through an Http callback
547+
548+
```ts
549+
this.columnDefinitions = [
550+
{
551+
id: 'prerequisites', name: 'Prerequisites', field: 'prerequisites',
552+
filterable: true,
553+
filter: {
554+
collectionLazy: (col: Column) => this.http.fetch('api/data/pre-requisites'),
555+
model: Filters.multipleSelect,
556+
}
557+
}
558+
];
559+
```
560+
542561
### Collection Watch
543562
We can enable the collection watch via the column filter `enableCollectionWatch` flag, or if you use a `collectionAsync` then this will be enabled by default. The collection watch will basically watch for any changes applied to the collection (any mutation changes like `push`, `pop`, `unshift`, ...) and will also watch for the `filter.collection` array replace, when any changes happens then it will re-render the Select Filter with the updated collection list.
544563

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@jest/types": "^29.6.3",
5050
"@lerna-lite/cli": "^4.0.0",
5151
"@lerna-lite/publish": "^4.0.0",
52-
"@slickgrid-universal/common": "^5.13.4",
52+
"@slickgrid-universal/common": "^5.14.0",
5353
"@types/jest": "^29.5.14",
5454
"@types/node": "^22.15.2",
5555
"conventional-changelog-conventionalcommits": "^8.0.0",

packages/aurelia-slickgrid/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
"@aurelia/runtime": "^2.0.0-beta.23",
5454
"@aurelia/runtime-html": "^2.0.0-beta.23",
5555
"@formkit/tempo": "^0.1.2",
56-
"@slickgrid-universal/common": "~5.13.4",
57-
"@slickgrid-universal/custom-footer-component": "~5.13.4",
58-
"@slickgrid-universal/empty-warning-component": "~5.13.4",
56+
"@slickgrid-universal/common": "~5.14.0",
57+
"@slickgrid-universal/custom-footer-component": "~5.14.0",
58+
"@slickgrid-universal/empty-warning-component": "~5.14.0",
5959
"@slickgrid-universal/event-pub-sub": "~5.13.0",
60-
"@slickgrid-universal/pagination-component": "~5.13.4",
61-
"@slickgrid-universal/row-detail-view-plugin": "~5.13.4",
60+
"@slickgrid-universal/pagination-component": "~5.14.0",
61+
"@slickgrid-universal/row-detail-view-plugin": "~5.14.0",
6262
"@slickgrid-universal/utils": "~5.12.0",
6363
"dequal": "^2.0.3",
6464
"sortablejs": "^1.15.6"

packages/demo/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
"@fnando/sparkline": "^0.3.10",
4444
"@formkit/tempo": "^0.1.2",
4545
"@popperjs/core": "^2.11.8",
46-
"@slickgrid-universal/common": "^5.13.4",
47-
"@slickgrid-universal/composite-editor-component": "^5.13.4",
48-
"@slickgrid-universal/custom-tooltip-plugin": "^5.13.4",
49-
"@slickgrid-universal/excel-export": "^5.13.4",
50-
"@slickgrid-universal/graphql": "^5.13.4",
51-
"@slickgrid-universal/odata": "^5.13.4",
52-
"@slickgrid-universal/row-detail-view-plugin": "^5.13.4",
53-
"@slickgrid-universal/rxjs-observable": "^5.13.4",
54-
"@slickgrid-universal/text-export": "^5.13.4",
46+
"@slickgrid-universal/common": "^5.14.0",
47+
"@slickgrid-universal/composite-editor-component": "^5.14.0",
48+
"@slickgrid-universal/custom-tooltip-plugin": "^5.14.0",
49+
"@slickgrid-universal/excel-export": "^5.14.0",
50+
"@slickgrid-universal/graphql": "^5.14.0",
51+
"@slickgrid-universal/odata": "^5.14.0",
52+
"@slickgrid-universal/row-detail-view-plugin": "^5.14.0",
53+
"@slickgrid-universal/rxjs-observable": "^5.14.0",
54+
"@slickgrid-universal/text-export": "^5.14.0",
5555
"aurelia": "^2.0.0-beta.23",
5656
"aurelia-slickgrid": "workspace:*",
5757
"bootstrap": "^5.3.5",

packages/demo/src/examples/slickgrid/example33.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ <h2>
1919

2020
<div class="subtitle" innerhtml.bind="subTitle"></div>
2121

22-
<div style="margin-bottom: 20px;">
23-
<label for="pinned-rows">Simulated Server Delay (ms): </label>
24-
<input type="number" id="server-delay" data-test="server-delay" style="width: 60px" value.bind="serverApiDelay" />
22+
<div class="row">
23+
<div class="col" style="margin-bottom: 20px">
24+
<label for="pinned-rows">Simulated Server Delay (ms): </label>
25+
<input type="number" id="server-delay" data-test="server-delay" style="width: 60px" value.bind="serverApiDelay" />
26+
</div>
27+
<div class="alert alert-info is-narrow col" class.bind="{ invisible: !showLazyLoading }" data-test="alert-lazy">
28+
Lazy loading collection...
29+
</div>
2530
</div>
2631

2732
<aurelia-slickgrid grid-id="grid33"

packages/demo/src/examples/slickgrid/example33.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from 'aurelia-slickgrid';
1919
import './example33.scss';
2020

21-
const NB_ITEMS = 500;
21+
const NB_ITEMS = 1000;
2222

2323
export class Example33 {
2424
title = 'Example 33: Regular & Custom Tooltips';
@@ -39,6 +39,7 @@ export class Example33 {
3939
dataset: any[] = [];
4040
hideSubTitle = false;
4141
serverApiDelay = 500;
42+
showLazyLoading = false;
4243

4344
constructor() {
4445
// define the grid options & columns and then create the grid itself
@@ -257,18 +258,32 @@ export class Example33 {
257258
},
258259
filter: {
259260
// collectionAsync: fetch(SAMPLE_COLLECTION_DATA_URL),
260-
collectionAsync: new Promise((resolve) => {
261-
window.setTimeout(() => {
262-
resolve(Array.from(Array(this.dataset.length).keys()).map(k => ({ value: k, label: `Task ${k}` })));
261+
// collectionAsync: new Promise((resolve) => {
262+
// window.setTimeout(() => {
263+
// resolve(Array.from(Array(dataset.value?.length).keys()).map((k) => ({ value: k, label: `Task ${k}` })));
264+
// });
265+
// }),
266+
collectionLazy: () => {
267+
this.showLazyLoading = true;
268+
269+
return new Promise((resolve) => {
270+
window.setTimeout(() => {
271+
this.showLazyLoading = false;
272+
resolve(Array.from(Array((this.dataset || []).length).keys()).map((k) => ({ value: k, label: `Task ${k}` })));
273+
}, this.serverApiDelay);
263274
});
264-
}),
275+
},
276+
// onInstantiated: (msSelect) => console.log('ms-select instance', msSelect),
265277
customStructure: {
266278
label: 'label',
267279
value: 'value',
268280
labelPrefix: 'prefix',
269281
},
270282
collectionOptions: {
271-
separatorBetweenTextLabels: ' '
283+
separatorBetweenTextLabels: ' ',
284+
},
285+
filterOptions: {
286+
minHeight: 70,
272287
},
273288
model: Filters.multipleSelect,
274289
operator: OperatorType.inContains,

packages/demo/src/styles.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ $primary-color: #0e6cfa;
4343
display: none;
4444
}
4545

46+
.invisible {
47+
opacity: 0;
48+
}
49+
4650
.btn-icon {
4751
display: inline-flex;
4852
align-items: center;

0 commit comments

Comments
 (0)