'show_count' => TRUE,
'expose_limit' => TRUE,
],
+ 'sort' => [],
'columns' => [],
],
];
+ // Supply default sort if no orderBy given in api params
+ if (!empty($this->savedSearch['api_entity']) && empty($this->savedSearch['api_params']['orderBy'])) {
+ $defaultSort = CoreUtil::getInfoItem($this->savedSearch['api_entity'], 'order_by');
+ if ($defaultSort) {
+ $display['settings']['sort'][] = [$defaultSort, 'ASC'];
+ }
+ }
foreach ($this->getSelectClause() as $key => $clause) {
$display['settings']['columns'][] = $this->configureColumn($clause, $key);
}
public static function getSchema() {
$schema = [];
$entities = \Civi\Api4\Entity::get()
- ->addSelect('name', 'title', 'title_plural', 'bridge_title', 'type', 'primary_key', 'description', 'label_field', 'icon', 'dao', 'bridge', 'ui_join_filters', 'searchable')
+ ->addSelect('name', 'title', 'title_plural', 'bridge_title', 'type', 'primary_key', 'description', 'label_field', 'icon', 'dao', 'bridge', 'ui_join_filters', 'searchable', 'order_by')
->addWhere('searchable', '!=', 'none')
->addOrderBy('title_plural')
->setChain([
parent: '^crmSearchAdminDisplay'
},
templateUrl: '~/crmSearchAdmin/displays/searchAdminDisplayGrid.html',
- controller: function($scope) {
+ controller: function($scope, searchMeta) {
var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
ctrl = this;
ctrl.display.settings = {
colno: '3',
limit: CRM.crmSearchAdmin.defaultPagerSize,
+ sort: [],
pager: {}
};
+ if (searchMeta.getEntity(ctrl.apiEntity).order_by) {
+ ctrl.display.settings.sort.push([searchMeta.getEntity(ctrl.apiEntity).order_by, 'ASC']);
+ }
}
ctrl.parent.initColumns({});
};
parent: '^crmSearchAdminDisplay'
},
templateUrl: '~/crmSearchAdmin/displays/searchAdminDisplayList.html',
- controller: function($scope) {
+ controller: function($scope, searchMeta) {
var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
ctrl = this;
ctrl.display.settings = {
style: 'ul',
limit: CRM.crmSearchAdmin.defaultPagerSize,
+ sort: [],
pager: {}
};
+ if (searchMeta.getEntity(ctrl.apiEntity).order_by) {
+ ctrl.display.settings.sort.push([searchMeta.getEntity(ctrl.apiEntity).order_by, 'ASC']);
+ }
}
ctrl.parent.initColumns({});
};
parent: '^crmSearchAdminDisplay'
},
templateUrl: '~/crmSearchAdmin/displays/searchAdminDisplayTable.html',
- controller: function($scope) {
+ controller: function($scope, searchMeta) {
var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
ctrl = this;
this.$onInit = function () {
if (!ctrl.display.settings) {
- ctrl.display.settings = _.extend({}, CRM.crmSearchAdmin.defaultDisplay.settings, {columns: null});
+ ctrl.display.settings = _.extend({}, _.cloneDeep(CRM.crmSearchAdmin.defaultDisplay.settings), {columns: null});
+ if (searchMeta.getEntity(ctrl.apiEntity).order_by) {
+ ctrl.display.settings.sort.push([searchMeta.getEntity(ctrl.apiEntity).order_by, 'ASC']);
+ }
}
// Displays created prior to 5.43 may not have this property
ctrl.display.settings.classes = ctrl.display.settings.classes || [];