Skip to content

Commit 529e290

Browse files
committed
Fixed error in rendering Filters for multiselect
1 parent 7fe0c05 commit 529e290

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Version 0.5.2 - Jan 4, 2021
2+
----------------------------
3+
- Fix: error in Filtering for multiselect
4+
5+
16
Version 0.5.1 - Jan 3, 2021
27
----------------------------
38
- Fix: error in argument validation in Pagination

src/Apphp/DataGrid/Filter.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,13 @@ public static function filter(): ?Filter
342342
}
343343
break;
344344
case 'user_role':
345-
if (is_string($value) && strlen($value) < 100) {
345+
if ((is_string($value) && strlen($value) < 100) || (is_array($value) && count($value) < 500)) {
346346
self::$filterFields[$key] = $value;
347-
$value = array_filter(explode(',', $value));
347+
348+
if (is_string($value)) {
349+
$value = array_filter(explode(',', $value));
350+
}
351+
348352
$whereHasClause = 'whereHas';
349353
$query = self::$query;
350354

@@ -620,7 +624,13 @@ public static function renderFields()
620624
if (config('datagrid.vueMultiselect')) {
621625
$filterFieldsContent .= '<vue-multiselect :id="\''.$htmlOptions['id'].'\'" :options=\''.json_encode($rolesList).'\' :values=\''.json_encode($role).'\' :placeholder-text="\'Select Role\'"></vue-multiselect>'.PHP_EOL;
622626
} else {
623-
$filterFieldsContent .= '';
627+
$roleValues = array_column($role, 'value');
628+
$filterFieldsContent .= '<select id="'.$htmlOptions['id'].'" name="'.$htmlOptions['id'].'[]" class="form-control form-control-sm" multiple>';
629+
foreach ($rolesList as $roleItem) {
630+
$selected = in_array($roleItem['value'], $roleValues) ? ' selected' : '';
631+
$filterFieldsContent .= '<option value="'.$roleItem['value'].'"'.$selected.'>'.$roleItem['label'].'</option>';
632+
}
633+
$filterFieldsContent .= '</select>';
624634
}
625635
break;
626636

0 commit comments

Comments
 (0)