Skip to content

Commit

Permalink
Sort filter fields by visible columns in index views (CFM-295) (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
arlen authored Jun 22, 2023
1 parent a182027 commit b2acb70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit b2acb70

Please sign in to comment.