LP1891699 AngJS grid column picker sorting user/berick/lp1891699-angjs-grid-col-picker-sorting
authorBill Erickson <berickxx@gmail.com>
Fri, 14 Aug 2020 19:06:29 +0000 (15:06 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 14 Aug 2020 19:06:41 +0000 (15:06 -0400)
AngularJS grid column picker displays colums in the following order:

1. Visible colums first, sorted alphabetically.
2. Non-visible columns second, sorted alphabetically.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/share/t_autogrid.tt2
Open-ILS/web/js/ui/default/staff/services/grid.js

index 38e9a00..5cbc5fb 100644 (file)
           [% l('Print Full Grid') %]
         </a></li>
         <li role="presentation" class="divider"></li>
-        <li ng-repeat="col in columns">
+        <li ng-repeat="col in columnsForPicker()">
           <a href title="{{col.idlclass}}" ng-click="toggleColumnVisibility(col)">
               <span ng-if="col.visible" 
                 class="label label-success">&#x2713;</span>
index ce84caa..c5a638d 100644 (file)
@@ -372,6 +372,22 @@ angular.module('egGridMod',
                 grid.controls = controls;
             }
 
+            // Visible columns sorted alphabetically followed by
+            // non-visible columns sorted.
+            $scope.columnsForPicker = function() {
+                if (!$scope.columns) { return []; }
+
+                var visible = $scope.columns
+                    .filter(function(c) { return c.visible; });
+                var invisible = $scope.columns
+                    .filter(function(c) { return !c.visible; });
+
+                visible.sort(function(a, b) { return a.label < b.label ? -1 : 1; });
+                invisible.sort(function(a, b) { return a.label < b.label ? -1 : 1; });
+
+                return visible.concat(invisible);
+            }
+
             // If a menu item provides its own HTML template, translate it,
             // using the menu item for the template scope.
             // note: $sce is required to avoid security restrictions and