Skip to content

Sort filter fields by visible columns in index views (CFM-295) #100

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/templates/Standard/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,14 @@

<!-- Search block -->
<?php if(isset($vv_searchable_attributes)): ?>
<?= $this->element('filter'); ?>
<?php
$filterArgs = array();
if(!empty($indexColumns)) {
// The keys of the $indexColumns are passed to the filters for sorting
$filterArgs['columnKeys'] = array_keys($indexColumns);
}
?>
<?= $this->element('filter', $filterArgs); ?>
<?php endif; ?>

<!-- Index table -->
Expand Down
10 changes: 9 additions & 1 deletion app/templates/element/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,15 @@
<?php
$field_booleans_columns = [];
$field_datetime_columns = [];


if(!empty($columnKeys)) {
// To make our filters consistently ordered with the index columns, sort the $vv_searchable_attributes
// by the columns.inc $indexColumns keys (passed in to this View element as "$columnKeys"). The fields found
// in columns.inc will be placed first in the resulting array. Throw out any fields from $columnKeys that didn't
// exist in the original $vv_searchable_attributes array.
$vv_searchable_attributes = array_intersect_key(array_replace(array_flip($columnKeys), $vv_searchable_attributes), $vv_searchable_attributes);
}

foreach($vv_searchable_attributes as $key => $options) {
if($options['type'] == 'boolean') {
$field_booleans_columns[$key] = $options;
Expand Down