Skip to content

Commit 4c6d1de

Browse files
committed
feat: add global defaultEditorOptions & defaultFilterOptions
1 parent 8fb24f6 commit 4c6d1de

9 files changed

+127
-16
lines changed

docs/column-functionalities/Editors.md

+29
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

+12-1
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

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

+14-4
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

+11
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

+13
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

+1-1
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: {

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

+14
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

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

+22-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- [Using an Inclusive Range](#using-an-inclusive-range-default-is-exclusive)
33
- [Using 2 dots (..) notation](#using-2-dots--notation)
44
- [Using a Slider Range](#using-a-slider-range-filter)
5-
- [Filter Options (`JQueryUiSliderOption` interface)](#filter-options-jqueryuislideroption-interface)
5+
- [Filter Options](#filter-options)
66
- [Using a Date Range](#using-a-date-range-filter)
77
- [Filter Options (`FlatpickrOption` interface)](#filter-options-flatpickroption-interface)
88
- [Update Filters Dynamically](Input-Filter.md#update-filters-dynamically)
@@ -71,7 +71,7 @@ The slider range filter is very useful if you can just want to use the mouse to
7171

7272
##### Component
7373
```ts
74-
import { Filters, Formatters, GridOption, JQueryUiSliderOption, OperatorType } from 'angular-slickgrid';
74+
import { Filters, Formatters, GridOption, SliderRangeOption, OperatorType } from 'angular-slickgrid';
7575

7676
export class GridBasicComponent implement OnInit {
7777
columnDefinitions: Column[];
@@ -93,9 +93,8 @@ export class GridBasicComponent implement OnInit {
9393
operator: OperatorType.rangeInclusive, // optional, defaults to exclusive
9494
params: { hideSliderNumbers: false }, // you can hide/show the slider numbers on both side
9595

96-
// you can also optionally pass any option of the jQuery UI Slider
97-
// however you can't override the `change` and `slide` events since they are used by the lib
98-
filterOptions: { min: 0, step: 5 } as JQueryUiSliderOption
96+
// you can also optionally pass any option of the Slider filter
97+
filterOptions: { sliderStartValue: 5 } as SliderRangeOption
9998
}
10099
},
101100
];
@@ -107,16 +106,29 @@ export class GridBasicComponent implement OnInit {
107106
}
108107
```
109108

110-
##### Filter Options (`JQueryUiSliderOption` interface)
111-
All the available options that can be provided as `filterOptions` to your column definitions can be found under this [FlatpickrOption interface](https://github.com/ghiscoding/slickgrid-universal/blob/master/packages/common/src/interfaces/jQueryUiSliderOption.interface.ts) and you should cast your `filterOptions` to that interface to make sure that you use only valid options of the jQueryUI Slider library.
109+
##### Filter Options
110+
All the available options that can be provided as `filterOptions` to your column definitions and you should try to cast your `filterOptions` to the specific interface as much as possible to make sure that you use only valid options of allowed by the targeted filter
112111

113112
```ts
114113
filter: {
115114
model: Filters.sliderRange,
116115
filterOptions: {
117-
min: 0,
118-
step: 5
119-
} as JQueryUiSliderOption
116+
sliderStartValue: 5
117+
} as SliderOption
118+
}
119+
```
120+
121+
#### Grid Option `defaultFilterOptions
122+
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
123+
124+
```ts
125+
this.gridOptions = {
126+
defaultFilterOptions: {
127+
// Note: that `date`, `select` and `slider` are combining both compound & range filters together
128+
date: { minDate: 'today' },
129+
select: { minHeight: 350 }, // typed as MultipleSelectOption
130+
slider: { sliderStartValue: 10 }
131+
}
120132
}
121133
```
122134

docs/column-functionalities/filters/Select-Filter.md

+11
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,17 @@ filter: {
565565
}
566566
```
567567

568+
#### Grid Option `defaultFilterOptions
569+
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
570+
```ts
571+
this.gridOptions = {
572+
defaultFilterOptions: {
573+
// Note: that `select` combines both multipleSelect & singleSelect
574+
select: { minHeight: 350 }, // typed as MultipleSelectOption
575+
}
576+
}
577+
```
578+
568579
### Multiple-select.js Options
569580
You can use any options from [Multiple-Select.js](http://wenzhixin.net.cn/p/multiple-select) and add them to your `filterOptions` property. However please note that this is a customized version of the original (all original [lib options](http://wenzhixin.net.cn/p/multiple-select/docs/) are available so you can still consult the original site for all options).
570581

0 commit comments

Comments
 (0)