Been reading about the various hacks to get the list view of the Cases module to sort descending using a specific field. Does anyone have a sec to help me with the proper way to do this? Also seems that these changes are not upgrade safe. Here are a few of the posts I have been reading.
My users want to have a sort in the account view. They always want them to be sorted by the account numbers going down irrespective of what options they have chosen to search by. So I was wondering if I can try this… Can I just change the aa_file_c to the name of the field I want to sort by in accounts and of course change any projects references to Accounts.
So FYI, that code is almost correct except for a couple of glitches:
The “Projects” module is “Project” not “Projects” despite every other module name being plural, so that needs corrected. It should also be named view.list.php and put in /custom/modules/project/views.
I don’t know where it is coming from, but my $_REQUEST[‘orderBy’] is never empty, so that code never fires (drives me crazy because I don’t know why it isn’t empty). For me, it is a column that you would NEVER want to sort by (a bool) so I just edited the code to also include that if it is that value, also repalce it with the desired sort field.
Otherwise, this code was pretty close. Took me nearly 2 years to finally get it working, I guess it wasn’t that big of a priority for me.
In each module Listview.
Click the column header that you like to be sorted on, once or twice (up/down sort) and then click Search. This makes the current sorting get saved. Just like a normal text search also can be saved with Search until it is Cleared.
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();
}