SearchKit - Sortable column fixes/improvements
authorColeman Watts <coleman@civicrm.org>
Mon, 4 Oct 2021 18:05:26 +0000 (14:05 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 4 Oct 2021 18:44:27 +0000 (14:44 -0400)
Fix sortable column headers on SearchKit admin tables
Make click-sortable column headers configurable

ext/search_kit/ang/crmSearchAdmin.module.js
ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js
ext/search_kit/ang/crmSearchAdmin/displays/searchAdminDisplayTable.html

index 248e3f5dfc6cd50373a8950263245cc5c8580f52..ee6bb116f5a10fc7cafb8d5c36e4b3e3520910ae 100644 (file)
       }
       function fieldToColumn(fieldExpr, defaults) {
         var info = parseExpr(fieldExpr),
-          field = _.findWhere(info.args, {type: 'field'}) || {},
+          field = (_.findWhere(info.args, {type: 'field'}) || {}).field || {},
           values = _.merge({
             type: 'field',
             key: info.alias,
           values.label = getDefaultLabel(fieldExpr);
         }
         if (defaults.sortable) {
-          values.sortable = field.type === 'Field';
+          values.sortable = field.type && field.type !== 'Pseudo';
         }
         return values;
       }
index 3d8feee3146b272f10afeeca76bccf135f1f9d39..9bb5c4f7f7400a01613fa7084b7582f11335cdc7 100644 (file)
         return !col.image && !col.rewrite && !col.link && !info.fn && info.args[0] && info.args[0].field && !info.args[0].field.readonly;
       };
 
+      this.canBeSortable = function(col) {
+        var expr = ctrl.getExprFromSelect(col.key),
+          info = searchMeta.parseExpr(expr),
+          arg = (_.findWhere(info.args, {type: 'field'}) || {});
+        return arg.field && arg.field.type !== 'Pseudo';
+      };
+
       // Aggregate functions (COUNT, AVG, MAX) cannot display as links, except for GROUP_CONCAT
       // which gets special treatment in APIv4 to convert it to an array.
       this.canBeLink = function(col) {
index c46776472610478a5ce1d6da8b676b3540405d49..b3234eadaa155b9e4f4f36781e145aa2baa0688c 100644 (file)
           <option value="text-right">{{:: ts('Right') }}</option>
         </select>
       </div>
+      <div class="form-inline" ng-if=":: $ctrl.parent.canBeSortable(col)">
+        <label title="{{:: ts('Allow user to click on header to sort table by this column') }}">
+          <input type="checkbox" ng-checked="col.sortable !== false" ng-click="col.sortable = col.sortable === false" >
+          {{:: ts('Sortable Header') }}
+        </label>
+      </div>
       <div ng-include="'~/crmSearchAdmin/displays/colType/' + col.type + '.html'"></div>
     </fieldset>
   </div>