Sorting fields in Subpanels within Accounts Module

Hi,


 

I have  been searching for ages for this and tried everything I could fine online but  nothing seems to work.

   

I have  custom modules setup as subpanels within Accounts. So under Accounts I can see  the subpanels. All I want to do is for each subpanel I have listed is to set a  default sort option by a specific field. I have tried the below code:

   

"\custom\modules\Accounts\metadata\subpaneldefs.php"

   

$layout_defs['Accounts']['subpanel_setup']['accounts_sits_technical_passwords_1']['sort_order']  = 'ASC';
  $layout_defs['Accounts']['subpanel_setup']['accounts_sits_technical_passwords_1']['sort_by']  = 'purpose_c';

   

I have tried  putting this in various places including extensions but nothing seems to work.  It seems to keep the last desired search option the user has selected.

   

Anyone  please help it is driving me mad. :)

PS: I am running CE 6.5.20

   

Thanks All 

  • 1) see in 
    custom/Extension/modules/<parent_module>/Ext/Layoutdefs/<parent_module_subpanel_module>.php

    Just modify below code
    'sort_order' => 'asc', 'sort_by' => 'name',

    2) see http://developer.sugarcrm.com/2012/10/08/customizing-the-query-used-for-a-subpanel/ for more advanced solution, you can adapt it to you needs.
  • Thanks guys. I managed to get this working. Any idea on how to do this on an actual module rather than the subpanel. I want to sort it by the same field. Thanks again 
  • I can help you again.

    for example, you need to sort records by field "my_custom_field_c" in Module Contacts.
    So you need to edit "/custom/modules/Contacts/views/view.list.php"
    edit function:
     function listViewPrepare() {
                $_REQUEST['orderBy'] = strtoupper('my_custom_field_c'); //set the field to order by NOTE: MUST BE ALL CAPS!
                $_REQUEST['sortOrder'] = 'DESC'; //set the order, ascending or descending
     
           parent::listViewPrepare(); //continue running the extended function's code
      }


    P.S. if my replies help you, you can at least hit "like" )))

  • Thanks mate. Sorry about the likes...... :)

    In the above reply do you mean I need to create the file view.list.php as it doesn't exist. Also do I just copy the code as it is and change the field accordingly?

  • You have to create folder views  "/custom/modules/Accounts/views".
    Then you have to copy file "/modules/Accounts/views/view.list.php" to "/custom/modules/Accounts/views/view.list.php"

    Then you have to edit function:
     function listViewPrepare() {
                $_REQUEST['orderBy'] = strtoupper('my_custom_field_c'); //set the field to order by NOTE: MUST BE ALL CAPS!
                $_REQUEST['sortOrder'] = 'DESC'; //set the order, ascending or descending
     
           parent::listViewPrepare(); //continue running the extended function's code
           //  $this->lv->targetList = true;  -- you may need to comment this line of code.

      }
  • Thanks. Can I do this for any custom module and use the contacts view.php as a template? Thanks again.
  • Yes, you can. I was not sure, so I checked it right now, and it works.
    in my case I have my custom module called "staff_Groups", so you can see all the changes I made in it (class name, function name etc.) after I copied the contacts view.php as a template.