Hi,
Is there a way to specify the default sort field and order for list views. Iâm looking for a definition that can be placed in custom vardef, listviewdefs or searchdefs files. Whilst the order is (mostly) remembered, if the âClear Searchâ button is clicked prior to a new search it always returns to the system default: date_entered rather than my chosen default.
There seems to be the ability to specify the sort_by and sort_order for subpanels, but nothing for listview, so it seems strange that there isnât something similar in list view. Following much googling Iâve also tried changing the $_REQUEST using a custom view.list.php file, but this doesnât work either.
I have tried this Advanced Filter in my Support Tickets, with Ascending, by Created Date, and I get the ones at the top that were created a month ago, not the ones created today.
public function preDisplay()
{
$userPreferenceOrder = $GLOBALS['current_user']->getPreference('listviewOrder', 'AOK_KnowledgeBase2_AOK_KNOWLEDGEBASE'); // you can get required category name from "user_preferences" table.
if(empty($userPreferenceOrder['orderBy']))
{
$_REQUEST['orderBy'] = 'field_name';
$_REQUEST['sortOrder'] = 'DESC';
}
parent::preDisplay();
}
Iâm not 100% sure but in 8.x preDisplay doesnât hit
Try to create public/legacy/custom/modules/Opportunities/Opportunity.php
and then extend Opportunity bean
class CustomOpportunity extends Opportunity
{
function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false, $parentbean = null, $singleSelect = false, $ifListForExport = false){
$ret_array = parent::create_new_list_query($order_by, $where, $filter, $params, $show_deleted, $join_type, true, $parentbean, $singleSelect, $ifListForExport);
if (isset($ret_array['order_by']) and strlen($ret_array['order_by'])){
}
else{
$ret_array['order_by'] = ' ORDER BY myfield DESC';
}
if ($return_array) {
return $ret_array;
}
}
}
then tell to suitecrm that opportunity bean point different file
Create CustomOpportunity.php in public/legacy/custom/Extension/application/Ext/Include/
if (isset($ret_array[âorder_byâ]) and strlen($ret_array[âorder_byâ])){
$ret_array[âorder_byâ] = â ORDER BY date_enteredDESCâ;
}
else{
$ret_array[âorder_byâ] = â ORDER BY date_enteredDESCâ;
}
before it was not hitting the else part so, just to check i put the same inside on the if part as well, it passes there, but not on the else part
this makes is only date_entered to be desc permanent, even if i try to change sort for name or other fields it does not take
You canât, you asked about default order, but if users customize order by (click on column arrows), default order (âelseâ in the code) doesnât hit