SearchKit - Only allow real fields to be sortable
[civicrm-core.git] / ext / search_kit / ang / crmSearchAdmin / displays / searchAdminDisplayTable.component.js
1 (function(angular, $, _) {
2 "use strict";
3
4 angular.module('crmSearchAdmin').component('searchAdminDisplayTable', {
5 bindings: {
6 display: '<',
7 apiEntity: '<',
8 apiParams: '<'
9 },
10 require: {
11 parent: '^crmSearchAdminDisplay'
12 },
13 templateUrl: '~/crmSearchAdmin/displays/searchAdminDisplayTable.html',
14 controller: function($scope) {
15 var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
16 ctrl = this;
17
18 this.tableClasses = [
19 {name: 'table', label: ts('Row Borders')},
20 {name: 'table-bordered', label: ts('Column Borders')},
21 {name: 'table-striped', label: ts('Even/Odd Stripes')}
22 ];
23
24 // Check if array conatains item
25 this.includes = _.includes;
26
27 // Add or remove an item from an array
28 this.toggle = function(collection, item) {
29 if (_.includes(collection, item)) {
30 _.pull(collection, item);
31 } else {
32 collection.push(item);
33 }
34 };
35
36 this.$onInit = function () {
37 if (!ctrl.display.settings) {
38 ctrl.display.settings = {
39 limit: CRM.crmSearchAdmin.defaultPagerSize,
40 classes: ['table'],
41 pager: {}
42 };
43 }
44 // Displays created prior to 5.43 may not have this property
45 ctrl.display.settings.classes = ctrl.display.settings.classes || [];
46 ctrl.parent.initColumns({label: true, sortable: true});
47 };
48
49 }
50 });
51
52 })(angular, CRM.$, CRM._);