chg: [component:CRUD] Pass searched value to the view and allow searching by hitting <enter>
parent
62426e0160
commit
ba65c60838
|
@ -341,6 +341,7 @@ class CRUDComponent extends Component
|
||||||
{
|
{
|
||||||
$queryConditions = [];
|
$queryConditions = [];
|
||||||
if (!empty($params['quickFilter']) && !empty($quickFilterFields)) {
|
if (!empty($params['quickFilter']) && !empty($quickFilterFields)) {
|
||||||
|
$this->Controller->set('quickFilterValue', $params['quickFilter']);
|
||||||
foreach ($quickFilterFields as $filterField) {
|
foreach ($quickFilterFields as $filterField) {
|
||||||
$likeCondition = false;
|
$likeCondition = false;
|
||||||
if (is_array($filterField)) {
|
if (is_array($filterField)) {
|
||||||
|
@ -352,6 +353,8 @@ class CRUDComponent extends Component
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$query->where(['OR' => $queryConditions]);
|
$query->where(['OR' => $queryConditions]);
|
||||||
|
} else {
|
||||||
|
$this->Controller->set('quickFilterValue', '');
|
||||||
}
|
}
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
'button' => __('Filter'),
|
'button' => __('Filter'),
|
||||||
'placeholder' => __('Enter value to search'),
|
'placeholder' => __('Enter value to search'),
|
||||||
'data' => '',
|
'data' => '',
|
||||||
|
'value' => $quickFilterValue,
|
||||||
'searchKey' => 'value'
|
'searchKey' => 'value'
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
var url = '/' + controller + '/' + action + additionalUrlParams + '?quickFilter=' + encodeURIComponent($('#quickFilterField-<?= h($tableRandomValue) ?>').val());
|
var url = '/' + controller + '/' + action + additionalUrlParams + '?quickFilter=' + encodeURIComponent($('#quickFilterField-<?= h($tableRandomValue) ?>').val());
|
||||||
executePagination(randomValue, url);
|
executePagination(randomValue, url);
|
||||||
});
|
});
|
||||||
$('#quickFilterField').on('keypress', function (e) {
|
$('#quickFilterField-' + randomValue).on('keypress', function (e) {
|
||||||
if(e.which === 13) {
|
if(e.which === 13) {
|
||||||
var url = '/' + controller + '/' + action + additionalUrlParams + '?quickFilter=' + encodeURIComponent($('#quickFilterField-<?= h($tableRandomValue) ?>').val());
|
var url = '/' + controller + '/' + action + additionalUrlParams + '?quickFilter=' + encodeURIComponent($('#quickFilterField-<?= h($tableRandomValue) ?>').val());
|
||||||
executePagination(randomValue, url);
|
executePagination(randomValue, url);
|
||||||
|
|
Loading…
Reference in New Issue