Default sort order field in subpanel not working 6.5

This is literally driving me insane.  I am trying to default sort a custom date field in a custom module subpanel.  Here's what I have done:

Background:

PI_Personal_Injury is the parent module

INV_Time_And_Expenses is the module subpanel

The field I am trying to sort by is called 'input_date_c'

In the parent module custom directory, I have edited the file: custom/modules/PI_Personal_Injury/Ext/Layoutdefs/layoutdefs.ext.php

Here are the contents:

$layout_defs["PI_Personal_Injury"]["subpanel_setup"]['pi_personal_injury_inv_time_and_expenses'] = array (

  'order' => 100,

  'module' => 'INV_Time_And_Expenses',

  'subpanel_name' => 'default',

  'sort_order' => 'asc',

  'sort_by' => 'input_date_c',

  'title_key' => 'LBL_PI_PERSONAL_INJURY_INV_TIME_AND_EXPENSES_FROM_INV_TIME_AND_EXPENSES_TITLE',

  'get_subpanel_data' => 'pi_personal_injury_inv_time_and_expenses',

  'top_buttons' =>

  array (

    0 =>

    array (

      'widget_class' => 'SubPanelTopButtonQuickCreate',

    ),

    1 =>

    array (

      'widget_class' => 'SubPanelTopSelectButton',

      'mode' => 'MultiSelect',

    ),

    2 =>

    array (

      'widget_class' => 'SubPanelTopCreateInvoiceButton',

    ),

  ),

);

After changing the sort_order, and the sort_by entries, I ran a QRR, cleared my browser cache, and even went so far as to reset the entire directory permissions and run a QRR again.  I had reached out to support prior to this nightmare endeavour, and they pointed me to this article:

http://stackoverflow.com/questions/30610322/how-to-change-default-sort-in-custom-subpanel-sugarcrm

That didn't work... upon further research, I found this article:

https://community.sugarcrm.com/thread/21956?q=Default%20sort%20order%20subpanel

After reading that article, I edited the file /custom/Extension/modules/PI_Personal_Injury/Ext/Layoutdefs/pi_personal_injury_inv_time_and_expenses_PI_Personal_Injury.php

Here are the contents:

$layout_defs["PI_Personal_Injury"]["subpanel_setup"]['pi_personal_injury_inv_time_and_expenses'] = array (

  'order' => 100,

  'module' => 'INV_Time_And_Expenses',

  'subpanel_name' => 'default',

  'sort_order' => 'asc',

  'sort_by' => 'input_date_c',

  'title_key' => 'LBL_PI_PERSONAL_INJURY_INV_TIME_AND_EXPENSES_FROM_INV_TIME_AND_EXPENSES_TITLE',

  'get_subpanel_data' => 'pi_personal_injury_inv_time_and_expenses',

  'top_buttons' =>

  array (

    0 =>

    array (

      'widget_class' => 'SubPanelTopButtonQuickCreate',

    ),

    1 =>

    array (

      'widget_class' => 'SubPanelTopSelectButton',

      'mode' => 'MultiSelect',

    ),

    2 =>

    array (

      'widget_class' => 'SubPanelTopCreateInvoiceButton',

    ),

  ),

);

...again, I ran a QRR, cleared my browser cache, reset the entire directory permissions and run a QRR again. And it STILL. DOESN'T. WORK.

Please help before another wireless mouse meets a horrifying, fiery end.....

I'm running 6.5.20 on a LAMP stack

  • Hello Toby,

      In your post, the way you tried it, it should have work. But you mentioned it didn't work. So, there is another way of doing it. You can follow this post:

      http://developer.sugarcrm.com/2012/10/08/customizing-the-query-used-for-a-subpanel/

      I don't know, whether you have implemented as mentioned in this post, but I have implemented the same in my instance and it works, so give it a try, if you haven't.

      I will give you a dummy example:

      Scenario: Here we are fetching all record of Bugs module on basis of select lead and sorting with custom field.

      First, format some of lines in your subpanel file lying inside following folder:

      custom/Extension/modules/Leads/Ext/Layoutdefs/custom_subpanel.php

      <?php

      $layout_defs['Leads']['subpanel_setup']['bugs'] =

            array('order' => 5,

                'module' => 'Bugs',

                'subpanel_name' => 'default',

                'get_subpanel_data' => 'function:get_bugs',

                'generate_select' => true,

                'title_key' => 'LBL_LEAD_BUGS',

                'top_buttons' => array(),

                'function_parameters' => array(

                    'import_function_file' => 'custom/modules/Leads/customBugsSubpanel.php',

                    'account_id' => $this->_focus->id,

                    'return_as_array' => 'true'

                ),

                'top_buttons' =>

                  array (

                    0 =>

                    array (

                      'widget_class' => 'SubPanelTopButtonQuickCreate',

                    ),

                    1 =>

                    array (

                      'widget_class' => 'SubPanelTopSelectButton',

                      'mode' => 'MultiSelect',

                    ),

                  ),

      );

      Then, add following code in a file located:

      custom/modules/Leads/customBugsSubpanel.php

      <?php

      function get_bugs($params) {

        $args = func_get_args();

        $lead_id = $args[0]['account_id'];

        $return_array['select'] = " SELECT bugs.*";

        $return_array['from'] = " FROM bugs as bugs ";

        $return_array['where'] = " WHERE bugs.deleted = '0'";

        $return_array['join'] = " inner join bugs_cstm as bc on bugs.id = bc.id_c inner join leads as leads on leads.id = bc.lead_id_c and leads.deleted = 0 and bc.lead_id_c = '" . $lead_id . "' order by bugs.custom_field_c";

        $return_array['join_tables'] = '';

        return $return_array;

      }

      And that's it. Do QRR and see the desired result. Let me know if you need any more help.

  • Did you ever get it to work?  I'm finding, at least for subpanels, you can change the default sort column but the order always defaults to ascending if there is no sort order in the session saved from the user manually clicking the header to sort.   sort_order setting doesn't work in the subpaneldef.php file, even in the non-custom directory.

  • Could you try to edit the file custom/modules/<MODULE>/clients/base/views/subpanel-list/subpanel-list.php

    with the following

    'orderBy' =>
    array (
    'field' => 'the_field_name_you_want_toSort',
    'direction' => 'desc',
    ),