Merge pull request #2073 from cuneytsenturk/master

Search & Filter set default filter.
This commit is contained in:
Cüneyt Şentürk 2021-06-01 14:59:56 +03:00 committed by GitHub
commit e2ca17fdb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 153 additions and 91 deletions

View File

@ -12,6 +12,8 @@ class SearchString extends Component
public $filters; public $filters;
public $filtered;
/** string */ /** string */
public $model; public $model;
@ -20,10 +22,11 @@ class SearchString extends Component
* *
* @return void * @return void
*/ */
public function __construct(string $model = '', $filters = false) public function __construct(string $model = '', $filters = false, $filtered = false)
{ {
$this->model = $model; $this->model = $model;
$this->filters = $filters; $this->filters = $filters;
$this->filtered = $filtered;
} }
/** /**

View File

@ -142,6 +142,11 @@ export default {
default: () => [], default: () => [],
description: 'List of filters' description: 'List of filters'
}, },
defaultFiltered: {
type: Array,
default: () => [],
description: 'List of filters'
},
dateConfig: null, dateConfig: null,
}, },
@ -195,7 +200,7 @@ export default {
}); });
} }
console.log('Focus :' + this.filter_last_step); //console.log('Focus :' + this.filter_last_step);
}, },
onInputDateSelected(selectedDates, dateStr, instance) { onInputDateSelected(selectedDates, dateStr, instance) {
@ -656,6 +661,57 @@ export default {
this.filter_index++; this.filter_index++;
} }
}, this); }, this);
} else if (this.defaultFiltered) {
this.defaultFiltered.forEach(function (filter) {
let option = '';
let operator = '=';
let value = '';
this.filter_list.forEach(function (_filter, i) {
let filter_values = this.convertOption(_filter.values);
if (_filter.key == filter.option) {
console.log('Filter YES');
option = _filter.value;
operator = filter.operator;
filter_values.forEach(function (_value) {
if (_value.key == filter.value) {
value = _value.value;
}
}, this);
this.selected_options.push(this.filter_list[i]);
console.log(operator);
this.selected_operator.push({
key: operator,
});
this.filter_list.splice(i, 1);
this.option_values[_filter.key] = filter_values;
filter_values.forEach(function (value, j) {
if (value.key == filter.value) {
this.selected_values.push(value);
this.option_values[_filter.key].splice(j, 1);
}
}, this);
}
}, this);
this.filtered.push({
option: option,
operator: operator,
value: value
});
this.filter_index++;
}, this);
} }
}, },

View File

@ -7,6 +7,9 @@
no-matching-data-text="{{ trans('general.no_matching_data') }}" no-matching-data-text="{{ trans('general.no_matching_data') }}"
value="{{ request()->get('search', null) }}" value="{{ request()->get('search', null) }}"
:filters="{{ json_encode($filters) }}" :filters="{{ json_encode($filters) }}"
@if($filtered)
:default-filtered="{{ json_encode($filtered) }}"
@endif
:date-config="{ :date-config="{
allowInput: true, allowInput: true,
altInput: true, altInput: true,