Skip to content

Commit 212c275

Browse files
authored
fix(filters): slider filter setValues really change input value (#621)
1 parent 3b3c643 commit 212c275

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

src/app/modules/angular-slickgrid/filters/__tests__/sliderFilter.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('SliderFilter', () => {
6363

6464
filter.init(filterArguments);
6565
filter.setValues(['2']);
66-
const filterElm = divContainer.querySelector('.search-filter.slider-container.filter-duration');
66+
const filterElm = divContainer.querySelector('.search-filter.slider-container.filter-duration input');
6767
filterElm.dispatchEvent(new CustomEvent('change'));
6868

6969
expect(spyCallback).toHaveBeenLastCalledWith(expect.anything(), { columnDef: mockColumn, operator: 'EQ', searchTerms: ['2'], shouldTriggerQuery: true });
@@ -74,7 +74,7 @@ describe('SliderFilter', () => {
7474

7575
filter.init(filterArguments);
7676
filter.setValues(3);
77-
const filterElm = divContainer.querySelector('.search-filter.slider-container.filter-duration');
77+
const filterElm = divContainer.querySelector('.search-filter.slider-container.filter-duration input');
7878
const mockEvent = new Event('change');
7979
Object.defineProperty(mockEvent, 'target', { writable: true, configurable: true, value: { value: '13' } });
8080
filterElm.dispatchEvent(mockEvent);

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export class CompoundSliderFilter implements Filter {
4141

4242
constructor(protected translate: TranslateService) { }
4343

44+
/** Getter for the Filter Operator */
45+
get columnFilter(): ColumnFilter {
46+
return this.columnDef && this.columnDef.filter || {};
47+
}
48+
4449
/** Getter to know what would be the default operator when none is specified */
4550
get defaultOperator(): OperatorType | OperatorString {
4651
return OperatorType.empty;
@@ -68,7 +73,7 @@ export class CompoundSliderFilter implements Filter {
6873

6974
/** Getter for the Filter Operator */
7075
get operator(): OperatorType | OperatorString {
71-
return this._operator || this.defaultOperator;
76+
return this._operator || this.columnFilter.operator || this.defaultOperator;
7277
}
7378

7479
/** Setter for the Filter Operator */
@@ -149,8 +154,8 @@ export class CompoundSliderFilter implements Filter {
149154
* destroy the filter
150155
*/
151156
destroy() {
152-
if (this.$filterElm) {
153-
this.$filterElm.off('input change').remove();
157+
if (this.$filterInputElm) {
158+
this.$filterInputElm.off('input change').remove();
154159
}
155160
}
156161

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

+19-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export class SliderFilter implements Filter {
2323
private _elementRangeInputId: string;
2424
private _elementRangeOutputId: string;
2525
private $filterElm: any;
26+
private $filterInputElm: any;
27+
private $filterNumberElm: any;
2628
grid: any;
2729
searchTerms: SearchTerm[];
2830
columnDef: Column;
@@ -86,7 +88,7 @@ export class SliderFilter implements Filter {
8688

8789
// step 3, subscribe to the change event and run the callback when that happens
8890
// also add/remove "filled" class for styling purposes
89-
this.$filterElm.change((e: any) => {
91+
this.$filterInputElm.change((e: any) => {
9092
const value = e && e.target && e.target.value;
9193
this._currentValue = +value;
9294

@@ -105,7 +107,7 @@ export class SliderFilter implements Filter {
105107
// if user chose to display the slider number on the right side, then update it every time it changes
106108
// we need to use both "input" and "change" event to be all cross-browser
107109
if (!this.filterParams.hideSliderNumber) {
108-
this.$filterElm.on('input change', (e: { target: HTMLInputElement }) => {
110+
this.$filterInputElm.on('input change', (e: { target: HTMLInputElement }) => {
109111
const value = e && e.target && e.target.value;
110112
if (value !== undefined && value !== null) {
111113
const elements = document.getElementsByClassName(this._elementRangeOutputId);
@@ -127,19 +129,18 @@ export class SliderFilter implements Filter {
127129
this.searchTerms = [];
128130
const clearedValue = this.filterParams.hasOwnProperty('sliderStartValue') ? this.filterParams.sliderStartValue : DEFAULT_MIN_VALUE;
129131
this._currentValue = +clearedValue;
130-
this.$filterElm.children('input').val(clearedValue);
131-
this.$filterElm.children('div.input-group-addon.input-group-append').children().html(clearedValue);
132-
this.$filterElm.val(clearedValue);
133-
this.$filterElm.trigger('change');
132+
this.$filterInputElm.val(clearedValue);
133+
this.$filterNumberElm.html(clearedValue);
134+
this.$filterInputElm.trigger('change');
134135
}
135136
}
136137

137138
/**
138139
* destroy the filter
139140
*/
140141
destroy() {
141-
if (this.$filterElm) {
142-
this.$filterElm.off('change').remove();
142+
if (this.$filterInputElm) {
143+
this.$filterInputElm.off('change').remove();
143144
}
144145
}
145146

@@ -154,10 +155,11 @@ export class SliderFilter implements Filter {
154155
/** Set value(s) on the DOM element */
155156
setValues(values: SearchTerm | SearchTerm[], operator?: OperatorType | OperatorString) {
156157
if (Array.isArray(values)) {
157-
this.$filterElm.val(values[0]);
158+
this.$filterInputElm.val(`${values[0]}`);
159+
this.$filterNumberElm.html(`${values[0]}`);
158160
this._currentValue = +values[0];
159161
} else if (values) {
160-
this.$filterElm.val(values);
162+
this.$filterInputElm.val(values);
161163
this._currentValue = +values;
162164
}
163165

@@ -207,10 +209,10 @@ export class SliderFilter implements Filter {
207209
* @param searchTerm optional preset search terms
208210
*/
209211
private createDomElement(filterTemplate: string, searchTerm?: SearchTerm) {
210-
const fieldId = this.columnDef && this.columnDef.id;
212+
const columnId = this.columnDef && this.columnDef.id;
211213
const minValue = this.filterProperties.hasOwnProperty('minValue') ? this.filterProperties.minValue : DEFAULT_MIN_VALUE;
212214
const startValue = this.filterParams.hasOwnProperty('sliderStartValue') ? this.filterParams.sliderStartValue : minValue;
213-
const $headerElm = this.grid.getHeaderRowColumn(fieldId);
215+
const $headerElm = this.grid.getHeaderRowColumn(columnId);
214216
$($headerElm).empty();
215217

216218
// create the DOM element & add an ID and filter class
@@ -224,9 +226,11 @@ export class SliderFilter implements Filter {
224226
}
225227
this._currentValue = +searchTermInput;
226228

227-
$filterElm.children('input').val(searchTermInput);
228-
$filterElm.children('div.input-group-addon.input-group-append').children().html(searchTermInput);
229-
$filterElm.data('columnId', fieldId);
229+
this.$filterInputElm = $filterElm.children('input');
230+
this.$filterNumberElm = $filterElm.children('div.input-group-addon.input-group-append').children();
231+
this.$filterInputElm.val(searchTermInput);
232+
this.$filterNumberElm.html(searchTermInput);
233+
$filterElm.data('columnId', columnId);
230234

231235
// if there's a search term, we will add the "filled" class for styling purposes
232236
if (searchTerm) {

0 commit comments

Comments
 (0)