0

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';
        }
    }
}

1 Answer 1

2

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

5
  • 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! Sep 10, 2018 at 11:49
  • 1
    Sure! Let us know how it goes. Sep 10, 2018 at 14:06
  • 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 Sep 11, 2018 at 3:22
  • Thanks all ! I realy want to use civicrm for it. I now use jQuery to change te results. Sep 18, 2018 at 11:58
  • Great Jan, so can we mark this as answered? Sep 18, 2018 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.