Trac – Ticket Sort Order

One of the things that bugs me with the default Trac install is the ticket list. By default the Active Tickets list sorts by value (?), milestone, type and time. Usually however I want to sort by Ticket # so I can see what I added most recently. Luckily Trac makes this easy as the Ticket ‘reports’ are driven by simply SQL queries.

Depending on your permissions when you click on an available report you should see several buttons at the top of your screen:

Trac Ticket Edit

Simply click Edit Report and you will be taken to a dialog where you can adjust the title of the report, the description and the query which pulls the data for the report!

The query for the default Active Ticket report looks like:

SELECT p.value AS __color__,
   id AS ticket, summary, component, version, milestone, t.type AS type,
   (CASE status WHEN 'assigned' THEN owner||' *' ELSE owner END) AS owner,
   time AS created,
   changetime AS _changetime, description AS _description,
   reporter AS _reporter
  FROM ticket t, enum p
  WHERE status IN ('new', 'assigned', 'reopened')
AND p.name = t.priority AND p.type = 'priority'
  ORDER BY p.value, milestone, t.type, time

Changing the sort order is a simple matter of adding an additional field to the ORDER BY:

SELECT p.value AS __color__,
   id AS ticket, summary, component, version, milestone, t.type AS type,
   (CASE status WHEN 'assigned' THEN owner||' *' ELSE owner END) AS owner,
   time AS created,
   changetime AS _changetime, description AS _description,
   reporter AS _reporter
  FROM ticket t, enum p
  WHERE status IN ('new', 'assigned', 'reopened')
AND p.name = t.priority AND p.type = 'priority'
  ORDER BY ticket desc, p.value, milestone, t.type, time

Since it’s simple SQL it’s very easy to create new reports as well. I’ve created a few new ones including one for closed tickets and several to pull up tickets based on certain components, etc.

Recent Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>