chg: [component:CRUD] Pass searched value to the view and allow searching by hitting <enter>

pull/37/head
mokaddem 2021-01-15 11:49:20 +01:00
parent 62426e0160
commit ba65c60838
3 changed files with 5 additions and 1 deletions

View File

@ -341,6 +341,7 @@ class CRUDComponent extends Component
{
$queryConditions = [];
if (!empty($params['quickFilter']) && !empty($quickFilterFields)) {
$this->Controller->set('quickFilterValue', $params['quickFilter']);
foreach ($quickFilterFields as $filterField) {
$likeCondition = false;
if (is_array($filterField)) {
@ -352,6 +353,8 @@ class CRUDComponent extends Component
}
}
$query->where(['OR' => $queryConditions]);
} else {
$this->Controller->set('quickFilterValue', '');
}
return $query;
}

View File

@ -23,6 +23,7 @@ echo $this->element('genericElements/IndexTable/index_table', [
'button' => __('Filter'),
'placeholder' => __('Enter value to search'),
'data' => '',
'value' => $quickFilterValue,
'searchKey' => 'value'
]
]

View File

@ -57,7 +57,7 @@
var url = '/' + controller + '/' + action + additionalUrlParams + '?quickFilter=' + encodeURIComponent($('#quickFilterField-<?= h($tableRandomValue) ?>').val());
executePagination(randomValue, url);
});
$('#quickFilterField').on('keypress', function (e) {
$('#quickFilterField-' + randomValue).on('keypress', function (e) {
if(e.which === 13) {
var url = '/' + controller + '/' + action + additionalUrlParams + '?quickFilter=' + encodeURIComponent($('#quickFilterField-<?= h($tableRandomValue) ?>').val());
executePagination(randomValue, url);