Answers.Body: <p>Unfortunately you can't use searchColumns to add column on contact search result. The layout in tpl doesn't respect the 'searchColumns' hook.</p>
  
  <p>However you can still use the hook by doing some additional UI setting or using javascript. Here are some alternate approaches</p>
  
  <ol>
  <li><p>Create a profile with same column as Find contact and set 'Visibility' to 'Expose publicly and for listings' and Results Column? to true for each field. Navigate to CiviCRM >> Administer >> Customize Data and Screens >> Search Preferences. Use the created profile as 'Default Contact Search Profile' option. Alter the code accordingly to adjust the result display.</p></li>
  <li><p>Add javascript to insert a column(td) for each row(tr) against each contact using the contact id defined in id or class for tr element. Iterate based on $rows assigned to tpl.</p></li>
  </ol>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-10T11:49:03.507Z
Answers.Text: Thanks for your answer, i will try it. Only if you add a header with "$headers['summary'] = array('name' => 'Summary');" it shows up in the results!
Answers.UserDisplayName: Jan-Derek Vos
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-10T14:06:37.080Z
Answers.Text: Sure! Let us know how it goes.
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-11T03:22:20.870Z
Answers.Text: I recommend you use Webform and views, makes it al sooooooo much easier, you get really fine granular control, I've given up on CIVIcrm core GUI, works much better with Drupal core display modules
Answers.UserDisplayName: Bruno  Vincent
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-18T11:58:34.210Z
Answers.Text: Thanks all ! I realy want to use civicrm for it. I now use jQuery to change te results.
Answers.UserDisplayName: Jan-Derek Vos
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-18T12:04:30.323Z
Answers.Text: Great Jan, so can we mark this as answered?
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-10T11:22:03.340Z
Answers.LastActivityDate: 2018-09-10T11:22:03.340Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>i try to add a custom column to the search results of "find contact". I use the hook "searchColumns", i can easily add a column with:</p>
  
  <pre><code>$headers['summary'] = array('name' =&gt; 'Summary');
  </code></pre>
  
  <p>, but when a add the data like:</p>
  
  <pre><code>$rows[$id]['summary'] = 'BBBBBBBBBB';
  </code></pre>
  
  <p>, the header shows up in the results but the data not.
  The whole code is:</p>
  
  <pre><code>function contactsearchshowsummary_civicrm_searchColumns($objectName, &amp;$headers, &amp;$rows, &amp;$selector){
      if('contact' == $objectName){
          $headers['summary'] = array('name' =&gt; 'Summary');
  
          foreach($rows as $id =&gt; $row){
              $rows[$id]['summary'] = 'BBBBBBBBBB';
          }
      }
  }
  </code></pre>
  
Tags: <hooks>
Title: Adding a column to search results
ThreadText: # Adding a column to search results
  
  (Asked by: username_0 on 2018-09-10)
  
  i try to add a custom column to the search results of "find contact". I use the hook "searchColumns", i can easily add a column with:
  $headers['summary'] = array('name' => 'Summary');
  
  , but when a add the data like:
  $rows[$id]['summary'] = 'BBBBBBBBBB';
  
  , the header shows up in the results but the data not.
  The whole code is:
  function contactsearchshowsummary_civicrm_searchColumns($objectName, &$headers, &$rows, &$selector){
      if('contact' == $objectName){
          $headers['summary'] = array('name' => 'Summary');
  
          foreach($rows as $id => $row){
              $rows[$id]['summary'] = 'BBBBBBBBBB';
          }
      }
  }
  
  **Tags:** hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-09-10. Score: 1
  
  Unfortunately you can't use searchColumns to add column on contact search result. The layout in tpl doesn't respect the 'searchColumns' hook.
  
  However you can still use the hook by doing some additional UI setting or using javascript. Here are some alternate approaches
  
  1. Create a profile with same column as Find contact and set 'Visibility' to 'Expose publicly and for listings' and Results Column? to true for each field. Navigate to CiviCRM >> Administer >> Customize Data and Screens >> Search Preferences. Use the created profile as 'Default Contact Search Profile' option. Alter the code accordingly to adjust the result display.
  2. Add javascript to insert a column(td) for each row(tr) against each contact using the contact id defined in id or class for tr element. Iterate based on $rows assigned to tpl.
  
  HTH
  
  Pradeep
  
  > **Comments:**
  > **username_0**: Thanks for your answer, i will try it. Only if you add a header with "$headers['summary'] = array('name' => 'Summary');" it shows up in the results!  
  > **username_1**: Sure! Let us know how it goes.  
  > **username_2**: I recommend you use Webform and views, makes it al sooooooo much easier, you get really fine granular control, I've given up on CIVIcrm core GUI, works much better with Drupal core display modules  
  > **username_0**: Thanks all ! I realy want to use civicrm for it. I now use jQuery to change te results.  
  > **username_1**: Great Jan, so can we mark this as answered?  
  
  ---
  
  