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

Commit efae856

Browse files
authored
Merge pull request #98 from ghiscoding/feat/filter-placeholder
feat(filters): add optional placeholder to all Filters
2 parents 40063b5 + 6590926 commit efae856

File tree

6 files changed

+89
-8
lines changed

6 files changed

+89
-8
lines changed

src/app/examples/custom-inputFilter.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { Column, Filter, FilterArguments, FilterCallback, SearchTerm, OperatorType, OperatorString } from './../modules/angular-slickgrid';
1+
import {
2+
Column,
3+
ColumnFilter,
4+
Filter,
5+
FilterArguments,
6+
FilterCallback,
7+
GridOption,
8+
OperatorType,
9+
OperatorString,
10+
SearchTerm,
11+
} from './../modules/angular-slickgrid';
212

313
// using external non-typed js libraries
414
declare var $: any;
@@ -14,6 +24,16 @@ export class CustomInputFilter implements Filter {
1424

1525
constructor() {}
1626

27+
/** Getter for the Filter Operator */
28+
get columnFilter(): ColumnFilter {
29+
return this.columnDef && this.columnDef.filter || {};
30+
}
31+
32+
/** Getter for the Grid Options pulled through the Grid Object */
33+
get gridOptions(): GridOption {
34+
return (this.grid && this.grid.getOptions) ? this.grid.getOptions() : {};
35+
}
36+
1737
/**
1838
* Initialize the Filter
1939
*/
@@ -83,7 +103,11 @@ export class CustomInputFilter implements Filter {
83103
* Create the HTML template as a string
84104
*/
85105
private buildTemplateHtmlString() {
86-
return `<input type="text" class="form-control search-filter" placeholder="Custom Filter">`;
106+
let placeholder = (this.gridOptions) ? (this.gridOptions.defaultFilterPlaceholder || '') : '';
107+
if (this.columnFilter && this.columnFilter.placeholder) {
108+
placeholder = this.columnFilter.placeholder;
109+
}
110+
return `<input type="text" class="form-control search-filter" placeholder="${placeholder}">`;
87111
}
88112

89113
/**

src/app/examples/grid-editor.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
OperatorType,
1616
} from './../modules/angular-slickgrid';
1717
import { CustomInputEditor } from './custom-inputEditor';
18+
import { CustomInputFilter } from './custom-inputFilter';
1819
import { Subject } from 'rxjs';
1920

2021
// using external non-typed js libraries
@@ -158,6 +159,10 @@ export class GridEditorComponent implements OnInit {
158159
model: CustomInputEditor,
159160
validator: myCustomTitleValidator, // use a custom validator
160161
},
162+
filter: {
163+
model: CustomInputFilter,
164+
placeholder: '&#128269; custom',
165+
},
161166
}, {
162167
id: 'duration',
163168
name: 'Duration (days)',

src/app/modules/angular-slickgrid/filters/compoundDateFilter.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { TranslateService } from '@ngx-translate/core';
22
import { mapFlatpickrDateFormatWithFieldType } from '../services/utilities';
3-
import { Column, Filter, FilterArguments, FilterCallback, FieldType, GridOption, OperatorString, OperatorType, SearchTerm } from './../models/index';
3+
import {
4+
Column,
5+
ColumnFilter,
6+
Filter,
7+
FilterArguments,
8+
FilterCallback,
9+
FieldType,
10+
GridOption,
11+
OperatorString,
12+
OperatorType,
13+
SearchTerm,
14+
} from './../models/index';
415
import Flatpickr from 'flatpickr';
516

617
// use Flatpickr from import or 'require', whichever works first
@@ -30,6 +41,11 @@ export class CompoundDateFilter implements Filter {
3041
return (this.grid && this.grid.getOptions) ? this.grid.getOptions() : {};
3142
}
3243

44+
/** Getter for the Filter Operator */
45+
get columnFilter(): ColumnFilter {
46+
return this.columnDef && this.columnDef.filter || {};
47+
}
48+
3349
set operator(op: OperatorType | OperatorString) {
3450
this._operator = op;
3551
}
@@ -133,7 +149,10 @@ export class CompoundDateFilter implements Filter {
133149
pickerOptions.enableTime = true;
134150
}
135151

136-
const placeholder = (this.gridOptions) ? (this.gridOptions.defaultFilterPlaceholder || '') : '';
152+
let placeholder = (this.gridOptions) ? (this.gridOptions.defaultFilterPlaceholder || '') : '';
153+
if (this.columnFilter && this.columnFilter.placeholder) {
154+
placeholder = this.columnFilter.placeholder;
155+
}
137156
const $filterInputElm: any = $(`<div class="flatpickr"><input type="text" class="form-control" data-input placeholder="${placeholder}"></div>`);
138157
this.flatInstance = ($filterInputElm[0] && typeof $filterInputElm[0].flatpickr === 'function') ? $filterInputElm[0].flatpickr(pickerOptions) : Flatpickr($filterInputElm, pickerOptions);
139158
return $filterInputElm;

src/app/modules/angular-slickgrid/filters/compoundInputFilter.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { TranslateService } from '@ngx-translate/core';
22
import { FieldType } from './../models/index';
3-
import { Column, Filter, FilterArguments, FilterCallback, GridOption, OperatorString, OperatorType, SearchTerm } from './../models/index';
3+
import {
4+
Column,
5+
ColumnFilter,
6+
Filter,
7+
FilterArguments,
8+
FilterCallback,
9+
GridOption,
10+
OperatorString,
11+
OperatorType,
12+
SearchTerm,
13+
} from './../models/index';
414

515
// using external non-typed js libraries
616
declare var $: any;
@@ -24,6 +34,11 @@ export class CompoundInputFilter implements Filter {
2434
return (this.grid && this.grid.getOptions) ? this.grid.getOptions() : {};
2535
}
2636

37+
/** Getter for the Filter Operator */
38+
get columnFilter(): ColumnFilter {
39+
return this.columnDef && this.columnDef.filter || {};
40+
}
41+
2742
/** Getter of input type (text, number, password) */
2843
get inputType() {
2944
return this._inputType;
@@ -108,7 +123,10 @@ export class CompoundInputFilter implements Filter {
108123
// ------------------
109124

110125
private buildInputHtmlString() {
111-
const placeholder = (this.gridOptions) ? (this.gridOptions.defaultFilterPlaceholder || '') : '';
126+
let placeholder = (this.gridOptions) ? (this.gridOptions.defaultFilterPlaceholder || '') : '';
127+
if (this.columnFilter && this.columnFilter.placeholder) {
128+
placeholder = this.columnFilter.placeholder;
129+
}
112130
return `<input class="form-control" type="${this._inputType || 'text'}" placeholder="${placeholder}" />`;
113131
}
114132

src/app/modules/angular-slickgrid/filters/inputFilter.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
22
Column,
3+
ColumnFilter,
34
Filter,
45
FilterArguments,
56
FilterCallback,
67
GridOption,
78
OperatorType,
89
OperatorString,
9-
SearchTerm
10+
SearchTerm,
1011
} from './../models/index';
1112

1213
// using external non-typed js libraries
@@ -23,6 +24,11 @@ export class InputFilter implements Filter {
2324

2425
constructor() {}
2526

27+
/** Getter for the Filter Operator */
28+
get columnFilter(): ColumnFilter {
29+
return this.columnDef && this.columnDef.filter || {};
30+
}
31+
2632
/** Getter of input type (text, number, password) */
2733
get inputType() {
2834
return this._inputType;
@@ -115,7 +121,10 @@ export class InputFilter implements Filter {
115121
*/
116122
private buildTemplateHtmlString() {
117123
const fieldId = this.columnDef && this.columnDef.id;
118-
const placeholder = (this.gridOptions) ? (this.gridOptions.defaultFilterPlaceholder || '') : '';
124+
let placeholder = (this.gridOptions) ? (this.gridOptions.defaultFilterPlaceholder || '') : '';
125+
if (this.columnFilter && this.columnFilter.placeholder) {
126+
placeholder = this.columnFilter.placeholder;
127+
}
119128
return `<input type="${this._inputType || 'text'}" class="form-control search-filter filter-${fieldId}" placeholder="${placeholder}">`;
120129
}
121130

src/app/modules/angular-slickgrid/models/columnFilter.interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ export interface ColumnFilter {
8080
*/
8181
params?: any;
8282

83+
/**
84+
* Placeholder text that can be used by some Filters.
85+
* Note that this will override the default placeholder configured in the global config
86+
*/
87+
placeholder?: string;
88+
8389
/** Step value of the filter, works only with Filters supporting it (input text, number, float, range, slider) */
8490
valueStep?: number | string;
8591
}

0 commit comments

Comments
 (0)