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

Commit 7bcf3ec

Browse files
authored
Merge pull request #1391 from ghiscoding/feat/default-editor-filter-grid-options
feat: add global `defaultEditorOptions` & `defaultFilterOptions`
2 parents 3109f9f + 17af831 commit 7bcf3ec

11 files changed

+276
-221
lines changed

docs/column-functionalities/Editors.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [onClick Action Editor (icon click)](#onclick-action-editor-icon-click)
99
- [AutoComplete Editor](editors/AutoComplete-Editor.md)
1010
- [Select (single/multi) Editors](editors/Select-Dropdown-Editor-(single,multiple).md)
11+
- [Editor Options](#editor-options)
1112
- [Validators](#validators)
1213
- [Custom Validator](#custom-validator)
1314
- [Disabling specific cell Edit](#disabling-specific-cell-edit)
@@ -446,6 +447,34 @@ You can also use the Slick Grid events as shown below
446447
}
447448
```
448449

450+
## Editor Options
451+
452+
#### Column Editor `editorOptions`
453+
Some of the Editors could receive extra options, which is mostly the case for Editors using external dependencies (e.g. `autocompleter`, `date`, `multipleSelect`, ...) you can provide options via the `editorOptions`, for example
454+
455+
```ts
456+
this.columnDefinitions = [{
457+
id: 'start', name: 'Start Date', field: 'start',
458+
editor: {
459+
model: Editors.date,
460+
editorOptions: { minDate: 'today' }
461+
}
462+
}];
463+
```
464+
465+
#### Grid Option `defaultEditorOptions
466+
You could also define certain options as a global level (for the entire grid or even all grids) by taking advantage of the `defaultEditorOptions` Grid Option. Note that they are set via the editor type as a key name (`autocompleter`, `date`, ...) and then the content is the same as `editorOptions` (also note that each key is already typed with the correct editor option interface), for example
467+
468+
```ts
469+
this.gridOptions = {
470+
defaultEditorOptions: {
471+
autocompleter: { debounceWaitMs: 150 }, // typed as AutocompleterOption
472+
date: { minDate: 'today' },
473+
longText: { cols: 50, rows: 5 }
474+
}
475+
}
476+
```
477+
449478
## Validators
450479
Each Editor needs to implement the `validate()` method which will be executed and validated before calling the `save()` method. Most Editor will simply validate that the value passed is correctly formed. The Float Editor is one of the more complex one and will first check if the number is a valid float then also check if `minValue` or `maxValue` was passed and if so validate against them. If any errors is found it will return an object of type `EditorValidatorOutput` (see the signature on top).
451480

docs/column-functionalities/editors/Autocomplete-Editor-(Kraaden-lib).md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ this.columnDefinitions = [
7979
// example with a fixed Collection (or collectionAsync)
8080
editorOptions: {
8181
showOnFocus: true, // display the list on focus of the autocomplete (without the need to type anything)
82-
},
82+
} as AutocompleterOption,
8383
enableRenderHtml: true, // this flag only works with a fixed Collection
8484
// collectionAsync: this.http.get(URL_COUNTRIES_COLLECTION),
8585
collection: [
@@ -104,6 +104,17 @@ editor: {
104104
}
105105
```
106106

107+
#### Grid Option `defaultEditorOptions
108+
You could also define certain options as a global level (for the entire grid or even all grids) by taking advantage of the `defaultEditorOptions` Grid Option. Note that they are set via the editor type as a key name (`autocompleter`, `date`, ...) and then the content is the same as `editorOptions` (also note that each key is already typed with the correct editor option interface), for example
109+
110+
```ts
111+
this.gridOptions = {
112+
defaultEditorOptions: {
113+
autocompleter: { debounceWaitMs: 150 }, // typed as AutocompleterOption
114+
}
115+
}
116+
```
117+
107118
## Using External Remote API
108119
You could also use external 3rd party Web API (can be JSONP query or regular JSON). This will make a much shorter result since it will only return a small subset of what will be displayed in the AutoComplete Editor or Filter. For example, we could use GeoBytes which provide a JSONP Query API for the cities of the world, you can imagine the entire list of cities would be way too big to download locally, so this is why we use such API.
109120

@@ -133,9 +144,10 @@ export class GridBasicComponent {
133144
fetch: (searchText, updateCallback) => {
134145
// assuming your API call returns a label/value pair
135146
yourAsyncApiCall(searchText) // typically you'll want to return no more than 10 results
136-
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]); })
137-
.catch(error => console.log('Error:', error);
138-
},
147+
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]))
148+
.catch(error => console.log('Error:', error));
149+
},
150+
}
139151
} as AutocompleterOption,
140152
},
141153
];
@@ -166,8 +178,9 @@ this.columnDefinitions = [
166178
fetch: (searchText, updateCallback) => {
167179
// assuming your API call returns a label/value pair
168180
yourAsyncApiCall(searchText) // typically you'll want to return no more than 10 results
169-
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]); })
170-
.catch(error => console.log('Error:', error);
181+
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]))
182+
.catch(error => console.log('Error:', error));
183+
}
171184
},
172185
} as AutocompleterOption,
173186
}
@@ -204,8 +217,9 @@ export class GridBasicComponent {
204217
minLength: 1,
205218
fetch: (searchText, updateCallback) => {
206219
yourAsyncApiCall(searchText) // typically you'll want to return no more than 10 results
207-
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]); })
208-
.catch(error => console.log('Error:', error);
220+
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]))
221+
.catch(error => console.log('Error:', error));
222+
}
209223
},
210224
renderItem: {
211225
layout: 'twoRows',
@@ -270,7 +284,7 @@ export class GridBasicComponent {
270284
},
271285
fetch: (searchText, updateCallback) => {
272286
yourAsyncApiCall(searchText) // typically you'll want to return no more than 10 results
273-
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]); })
287+
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]))
274288
.catch(error => console.log('Error:', error);
275289
},
276290
renderItem: {
@@ -351,14 +365,10 @@ export class GridBasicComponent {
351365
editorOptions: {
352366
minLength: 3, // minimum count of character that the user needs to type before it queries to the remote
353367
fetch: (searchText, updateCallback) => {
354-
$.ajax({
355-
url: 'http://gd.geobytes.com/AutoCompleteCity',
356-
dataType: 'jsonp',
357-
data: {
358-
q: searchText // geobytes requires a query with "q" queryParam representing the chars typed (e.g.: gd.geobytes.com/AutoCompleteCity?q=van
359-
},
360-
success: (data) => updateCallback(data)
361-
});
368+
// assuming your API call returns a label/value pair
369+
yourAsyncApiCall(searchText) // typically you'll want to return no more than 10 results
370+
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]))
371+
.catch(error => console.log('Error:', error));
362372
}
363373
},
364374
},
@@ -371,16 +381,10 @@ export class GridBasicComponent {
371381
editorOptions: {
372382
minLength: 3, // minimum count of character that the user needs to type before it queries to the remote
373383
fetch: (searchText, updateCallback) => {
374-
$.ajax({
375-
url: 'http://gd.geobytes.com/AutoCompleteCity',
376-
dataType: 'jsonp',
377-
data: {
378-
q: searchText
379-
},
380-
success: (data) => {
381-
updateCallback(data);
382-
}
383-
});
384+
// assuming your API call returns a label/value pair
385+
yourAsyncApiCall(searchText) // typically you'll want to return no more than 10 results
386+
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]))
387+
.catch(error => console.log('Error:', error));
384388
}
385389
},
386390
}

docs/column-functionalities/editors/Date-Editor-(flatpickr).md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- See the [Editors - Wiki](../Editors.md) for more general info about Editors (validators, event handlers, ...)
55

66
### Information
7-
The Date Editor is provided through an external library named [Flatpickr](https://flatpickr.js.org/examples/) and all options from that library can be added to your `editorOptions` (see below [Editor Options]()), so in order to add things like minimum date, disabling dates, ... just review all the [Flatpickr Examples](https://flatpickr.js.org/examples/) and then add them into `editorOptions`. Also just so you know, `editorOptions` is use by all other editors as well to expose external library like Flatpickr, Multiple-Select.js, etc...
7+
The Date Editor is provided through an external library named [Flatpickr](https://flatpickr.js.org/examples/) and all options from that library can be added to your `editorOptions` (see below), so in order to add things like minimum date, disabling dates, ... just review all the [Flatpickr Examples](https://flatpickr.js.org/examples/) and then add them into `editorOptions`. Also just so you know, `editorOptions` is use by all other editors as well to expose external library like Flatpickr, Multiple-Select.js, etc...
88

99
### Demo
1010
[Demo Page](https://ghiscoding.github.io/Angular-Slickgrid/#/editor) | [Demo Component](https://github.com/ghiscoding/angular-slickgrid/blob/master/src/app/examples/grid-editor.component.ts)
@@ -22,9 +22,8 @@ defineGrid() {
2222
editor: {
2323
model: Editors.date,
2424
editorOptions: {
25-
editorOptions: {
26-
minDate: 'today',
27-
disable: [(date: Date) => this.isWeekendDay(date)], // disable weekend days (Sat, Sunday)
25+
minDate: 'today',
26+
disable: [(date: Date) => this.isWeekendDay(date)], // disable weekend days (Sat, Sunday)
2827
} as FlatpickrOption,
2928
},
3029
},
@@ -37,6 +36,17 @@ isWeekendDay(date: Date): boolean {
3736
}
3837
```
3938

39+
#### Grid Option `defaultEditorOptions
40+
You could also define certain options as a global level (for the entire grid or even all grids) by taking advantage of the `defaultEditorOptions` Grid Option. Note that they are set via the editor type as a key name (`autocompleter`, `date`, ...) and then the content is the same as `editorOptions` (also note that each key is already typed with the correct editor option interface), for example
41+
42+
```ts
43+
this.gridOptions = {
44+
defaultEditorOptions: {
45+
date: { minDate: 'today' }, // typed as FlatpickrOption
46+
}
47+
}
48+
```
49+
4050
### Custom Validator
4151
You can add a Custom Validator from an external function or inline (inline is shown below and comes from [Example 3](https://ghiscoding.github.io/Angular-Slickgrid/#/editor))
4252
```ts

docs/column-functionalities/editors/LongText-Editor-(textarea).md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ defineGrid() {
3939
}
4040
```
4141

42+
#### Grid Option `defaultEditorOptions
43+
You could also define certain options as a global level (for the entire grid or even all grids) by taking advantage of the `defaultEditorOptions` Grid Option. Note that they are set via the editor type as a key name (`autocompleter`, `date`, ...) and then the content is the same as `editorOptions` (also note that each key is already typed with the correct editor option interface), for example
44+
45+
```ts
46+
this.gridOptions = {
47+
defaultEditorOptions: {
48+
longText: { cols: 50, rows: 5 }, // typed as LongTextEditorOption
49+
}
50+
}
51+
```
52+
4253
### Custom Validator
4354
You can add a Custom Validator, from an external function or inline.
4455
```ts

docs/column-functionalities/editors/Select-Dropdown-Editor-(single,multiple).md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ editor: {
4646
} as MultipleSelectOption
4747
}
4848
```
49+
50+
#### Grid Option `defaultEditorOptions
51+
You could also define certain options as a global level (for the entire grid or even all grids) by taking advantage of the `defaultEditorOptions` Grid Option. Note that they are set via the editor type as a key name (`autocompleter`, `date`, ...) and then the content is the same as `editorOptions` (also note that each key is already typed with the correct editor option interface), for example
52+
53+
```ts
54+
this.gridOptions = {
55+
defaultEditorOptions: {
56+
// Note: that `select` combines both multipleSelect & singleSelect
57+
select: { minHeight: 350 }, // typed as MultipleSelectOption
58+
}
59+
}
60+
```
61+
4962
### Complex Object
5063
If your `field` string has a dot (.) it will automatically assume that it is dealing with a complex object. There are however some options you can use with a complex object, the following options from the `ColumnEditor` might be useful to you
5164
```ts

docs/column-functionalities/filters/Autocomplete-Filter-(Kraaden-lib).md

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class GridBasicComponent implements OnInit {
6868
```
6969

7070
### Filter Options (`AutocompleterOption` interface)
71-
All the available options that can be provided as `filterOptions` to your column definitions can be found under this [AutocompleterOption interface](https://github.com/ghiscoding/slickgrid-universal/blob/master/packages/common/src/interfaces/autocompleterOption.interface.ts) and you should cast your `filterOptions` to that interface to make sure that you use only valid options of the jQueryUI autocomplete library.
71+
All the available options that can be provided as `filterOptions` to your column definitions can be found under this [AutocompleterOption interface](https://github.com/ghiscoding/slickgrid-universal/blob/master/packages/common/src/interfaces/autocompleterOption.interface.ts) and you should cast your `filterOptions` to that interface to make sure that you use only valid options of the autocomplete library.
7272

7373
```ts
7474
filter: {
@@ -118,14 +118,10 @@ export class GridBasicComponent implements OnInit {
118118
editorOptions: {
119119
minLength: 3, // minimum count of character that the user needs to type before it queries to the remote
120120
fetch: (searchText, updateCallback) => {
121-
$.ajax({
122-
url: 'http://gd.geobytes.com/AutoCompleteCity',
123-
dataType: 'jsonp',
124-
data: {
125-
q: searchText // geobytes requires a query with "q" queryParam representing the chars typed (e.g.: gd.geobytes.com/AutoCompleteCity?q=van
126-
},
127-
success: (data) => updateCallback(data)
128-
});
121+
// assuming your API call returns a label/value pair
122+
yourAsyncApiCall(searchText) // typically you'll want to return no more than 10 results
123+
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]))
124+
.catch(error => console.log('Error:', error));
129125
}
130126
},
131127
},
@@ -138,18 +134,12 @@ export class GridBasicComponent implements OnInit {
138134
filterOptions: {
139135
minLength: 3, // minimum count of character that the user needs to type before it queries to the remote
140136
fetch: (searchText, updateCallback) => {
141-
$.ajax({
142-
url: 'http://gd.geobytes.com/AutoCompleteCity',
143-
dataType: 'jsonp',
144-
data: {
145-
q: searchText
146-
},
147-
success: (data) => {
148-
updateCallback(data);
149-
}
150-
});
151-
}
152-
},
137+
// assuming your API call returns a label/value pair
138+
yourAsyncApiCall(searchText) // typically you'll want to return no more than 10 results
139+
.then(result => updateCallback((results.length > 0) ? results : [{ label: 'No match found.', value: '' }]))
140+
.catch(error => console.log('Error:', error));
141+
},
142+
}
153143
}
154144
}
155145
];

docs/column-functionalities/filters/Compound-Filters.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ export class AppComponent {
175175
}
176176
```
177177

178+
#### Grid Option `defaultFilterOptions
179+
You could also define certain options as a global level (for the entire grid or even all grids) by taking advantage of the `defaultFilterOptions` Grid Option. Note that they are set via the filter type as a key name (`autocompleter`, `date`, ...) and then the content is the same as `filterOptions` (also note that each key is already typed with the correct filter option interface), for example
180+
181+
```ts
182+
this.gridOptions = {
183+
defaultFilterOptions: {
184+
// Note: that `date`, `select` and `slider` are combining both compound & range filters together
185+
date: { minDate: 'today' },
186+
select: { minHeight: 350 }, // typed as MultipleSelectOption
187+
slider: { sliderStartValue: 10 }
188+
}
189+
}
190+
```
191+
178192
### Compound Operator List (custom list)
179193
Each Compound Filter will try to define the best possible Operator List depending on what Field Type you may have (for example we can have StartsWith Operator on a string but not on a number). If you want to provide your own custom Operator List to a Compound Filter, you can do that via the `compoundOperatorList` property (also note that your Operator must be a valid OperatorType/OperatorString).
180194

0 commit comments

Comments
 (0)