CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Default sort order for custom search
Pages: [1]

Author Topic: Default sort order for custom search  (Read 483 times)

Erich

  • I post occasionally
  • **
  • Posts: 84
  • Karma: 1
Default sort order for custom search
September 13, 2012, 06:23:27 am
I have a custom search, the definition of which includes the lines:
$this->_columns = array( ts('')        => 'contact_id'  ,
                         ts('Name')    => 'sort_name'   ,
                         (etc.)



I noticed that the default sort field for the search result is the name field -- unlike Smart Groups, where the default sort field for the search result is the contact id.

Well, adding "order by contact_id" to my where clause results in a "Database Error Code: Column 'contact_id' in order clause is ambiguous, 1052" error.  Changing to "order by contact_a.id" (to match the syntax in the SELECT statement) results in a "You have an error in your SQL syntax" message (the generated query includes "order by contact_a.id ORDER BY sort_name asc LIMIT 0, 50").

If I change
   $this->_columns = array( ts('')        => 'contact_id'
to
   $this->_columns = array( ts('Index')   => 'contact_id'
I get the ordering I want, but of course I also get a column heading and value for the otherwise-hidden index column.

Is there any way to specify a hidden field as the default ORDER BY field?

Erich

  • I post occasionally
  • **
  • Posts: 84
  • Karma: 1
Re: Default sort order for custom search
October 15, 2012, 07:26:05 am
There's no way to specify a hidden field as the default ORDER BY field?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Default sort order for custom search

This forum was archived on 2017-11-26.