Answers.Body: <p>I found quick hack to add sort in <code>CRM_Case_Selector_Search</code> class file. Though its not good practice to touch core, I could not find better option to get around this problem</p>
  
  <pre><code>  public function &amp;getRows($action, $offset, $rowCount, $sort, $output = NULL) {
         //adding sort here for descending
          $sort-&gt;_vars[1] = array('name'=&gt;'case_id',
                                  'direction'=&gt;CRM_Utils_Sort::DESCENDING,
                                  'title'=&gt;ts('Case ID')
                                 );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-21T16:48:30.900Z
Answers.LastActivityDate: 2017-12-21T16:48:30.900Z
Answers.UserDisplayName: Developer
Body: <p>I'm trying to display cases in reverse order in contact summary Cases Tab. I tried using hook called <code>civicrm_searchColumns( $objectName, &amp;$headers,  &amp;$values, &amp;$selector )</code></p>
  
  <p>and changed the values using <code>$values = array_reverse($values);</code>. but some contacts got more than 100 cases split into different pages. using this hook I cant get cases in <code>ORDER BY id DESC</code> order.</p>
  
  <p>I checked relevant php file <code>CRM_Case_Page_Tab</code>. Its using controller in browse function like below</p>
  
  <pre><code>  public function browse() {
  
      $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search', ts('Case'), CRM_Core_Action::BROWSE);
      $controller-&gt;setEmbedded(TRUE);
      $controller-&gt;reset();
      $controller-&gt;set('limit', 20);
      $controller-&gt;set('force', 1);
      $controller-&gt;set('context', 'case');
      $controller-&gt;process();
      $controller-&gt;run();
  </code></pre>
  
  <p>Can anyone suggest me is there any option to add sort by to this controller object for case id in descending order?</p>
  
  <p>or where to add this order by case id to the actual query?</p>
  
  <p>TIA</p>
  
Tags: <civicase><civicrm-home><contact-view>
Title: Display cases in contact summary tab in reverse order (ORDER BY id DESC)
ThreadText: # Display cases in contact summary tab in reverse order (ORDER BY id DESC)
  
  (Asked by: username_0 on 2017-12-21)
  
  I'm trying to display cases in reverse order in contact summary Cases Tab. I tried using hook called civicrm_searchColumns( $objectName, &$headers,  &$values, &$selector )
  and changed the values using $values = array_reverse($values);. but some contacts got more than 100 cases split into different pages. using this hook I cant get cases in ORDER BY id DESC order.
  I checked relevant php file CRM_Case_Page_Tab. Its using controller in browse function like below
    public function browse() {
  
      $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search', ts('Case'), CRM_Core_Action::BROWSE);
      $controller->setEmbedded(TRUE);
      $controller->reset();
      $controller->set('limit', 20);
      $controller->set('force', 1);
      $controller->set('context', 'case');
      $controller->process();
      $controller->run();
  
  Can anyone suggest me is there any option to add sort by to this controller object for case id in descending order?
  or where to add this order by case id to the actual query?
  TIA
  
  **Tags:** civicase, civicrm-home, contact-view
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-12-21. Score: 1
  
  I found quick hack to add sort in CRM_Case_Selector_Search class file. Though its not good practice to touch core, I could not find better option to get around this problem
    public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
         //adding sort here for descending
          $sort->_vars[1] = array('name'=>'case_id',
                                  'direction'=>CRM_Utils_Sort::DESCENDING,
                                  'title'=>ts('Case ID')
                                 );
  
  
  ---
  
  