Fix default sort ref #110
this adds code to the model for list views and related list views so that if no sort order is manually specified (someone hasn't clicked a column header) then it checks to see if the performance preference for default sorting is turned on and uses the sort order specified for the module. ref issue #110 (closed)
Merge request reports
Activity
mentioned in commit 052885da
@uma.s Do you know why this patch was removed when the v7 code was dropped in? Re-introducing this would be very helpful for some of my customers.
@lord_alan I noticed that this change was introduced 5 years back, where we have introduced the api getOrderBy() in core file data/CRMEntity.php which checks through the performance settings for default sorting and returns.
@uma.s Thanks - but the getOrderBy() in CRMEntity.php doesn't seem to work at all! I was looking at it this morning. In my test system, none of the lists or related lists seem to follow the $focus->default_order_by when LISTVIEW_DEFAULT_SORTING is enabled.
If I make a few changes (similar to this patch) to the above two files however then I can get sorting to work as expected:
ListView Model:
} else if(empty($orderBy) && empty($sortOrder) && $moduleName != "Users") { if (PerformancePrefs::getBoolean('LISTVIEW_DEFAULT_SORTING', true)) { $orderBy = $moduleFocus->default_order_by; $qualifiedOrderBy = $orderBy; $orderByField = $moduleModel->getFieldByColumn($orderBy); if($orderByField) { $qualifiedOrderBy = $moduleModel->getOrderBySql($qualifiedOrderBy); $sortOrder = $moduleFocus->default_sort_order; $listQuery .= ' ORDER BY '.$qualifiedOrderBy.' '.$sortOrder; } else { $listQuery .= ' ORDER BY vtiger_crmentity.modifiedtime DESC'; } } else { //List view will be displayed on recently created/modified records $listQuery .= ' ORDER BY vtiger_crmentity.modifiedtime DESC'; } }
and RelationListView model:
} else if(!$orderBy & PerformancePrefs::getBoolean('LISTVIEW_DEFAULT_SORTING', true)) { $entityModule = CRMEntity::getInstance($relationModuleName); $orderBy = $entityModule->default_order_by; $qualifiedOrderBy = $orderBy; $orderByField = $relationModule->getFieldByColumn($orderBy); if($orderByField) { $qualifiedOrderBy = $relationModule->getOrderBySql($qualifiedOrderBy); $sortOrder = $entityModule->default_sort_order; $query .= ' ORDER BY '.$qualifiedOrderBy.' '.$sortOrder; } else { $query .= ' ORDER BY vtiger_crmentity.modifiedtime DESC'; } } else if($relationModuleName == 'HelpDesk' && empty($orderBy) && empty($sortOrder) && $moduleName != "Users") { $query .= ' ORDER BY vtiger_crmentity.modifiedtime DESC'; }
@lord_alan Thanks! for the patch, will consider this in the pipeline and make it to next release.