Default Sort Order for Listview

Has anyone had any success setting the default sort order for listview. Currently, my “projects” listview is sorting by “actual project” (which is a bool) and i would like it to sort by “aa_file_c” which is an alpha-numeric field. Descending, by the way. I found some information on the sugar forums, but nothing I was able to make work.

thanks,
sieberta

Hi Sieberta,

Can you provide some examples of what code changes you have tried to make that are not working?

Thanks,

Will.

I’m so tired of fighting this… it shouldn’t be that hard.

I edited custom/modules/Project/views/view.list.php

It was:

<?php 

// custom/modules/Project/views/view.list.php

require_once('include/MVC/View/views/view.list.php');
require_once('custom/modules/Project/ProjectListViewSmarty.php');

class ProjectViewList extends ViewList {
	
	function ProjectViewList(){
		parent::ViewList();
	}
	
	function preDisplay(){
		$this->lv = new ProjectListViewSmarty();
	}
}

?>

And I made it:

<?php 

// custom/modules/Project/views/view.list.php

require_once('include/MVC/View/views/view.list.php');
require_once('custom/modules/Project/ProjectListViewSmarty.php');

class ProjectViewList extends ViewList {
	
	function ProjectViewList(){
		parent::ViewList();
	}
	
	function preDisplay(){
		$this->lv = new ProjectListViewSmarty();
	}
}

class CustomProjectViewList extends ProjectViewList{
	function CustomProjectViewList(){
		parent::ProjectViewList();
	}
	function listViewPrepare() {
		if(!isset($_REQUEST['orderBy'])) {
			$_REQUEST['orderBy'] = 'AA_FILE_C';
		}
		if(!isset($_REQEUST['sortOrder']) {
			$_REQUEST['sortOrder'] = 'DESC';
		}
		parent::listViewPrepare();
	}
}
?>

The result is that nothing shows up when I load the Project module listview… it is a white blank screen. There is nothing in the SugarLog file or the apache log file that indicates an error.

One of many sources: http://forums.sugarcrm.com/f3/default-sort-order-list-view-43391/index2.html

Probably the query returning the values joins other table and if so you must specify from where the table.AA_FILE_C field belongs

If you want to respect user preferences then use the following code to apply default sorting order:

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();
    }