Edgewall Software

Opened 15 years ago

Last modified 6 years ago

#3080 new enhancement

Custom field sorts only as text

Reported by: aroach@… Owned by:
Priority: normal Milestone: next-major-releases
Component: general Version: 0.9.5
Severity: normal Keywords: tracobject fieldrefactoring
Cc: jhn@…, leho@… Branch:
Release Notes:
API Changes:
Internal Changes:


I've created a custom field to enable me to manually order tickets. I've used integers as the value, but it seems to be sorting as text.

For instance, the order shows up like 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9

Would like to be able to sort numerical values through custom fields.

Attachments (0)

Change History (13)

comment:1 by sid, 15 years ago

What is the type you have defined for the field in trac.ini? Looking at TracTicketsCustomFields, there is no integer type for a custom field, so the sorting you are seeing is probably the expected behavior.

A hack to get around this is to pad the field with zeros. So 01, 02, 03, …, 10, 11.

comment:2 by Christian Boos, 15 years ago

Keywords: tracobject added
Milestone: 1.0

More custom field types are needed.

comment:3 by richard.dunlap@…, 13 years ago

In particular, types for userID (resulting in a combo box populated by Trac user ids) and datetime (entry TBD, but displayed as an offset from current datetime a la the creation and last update datetimes) would be very useful.

comment:4 by bobbysmith007@…, 12 years ago

I will second the need for numeric custom fields.

If they were added and a reasonable patch for the query module were submitted, would this be likely to be accepted?

comment:5 by anonymous, 12 years ago

+1 for this fix. The lack of sorting impacts the efficiency of th:TimingAndEstimationPlugin

Last edited 7 years ago by Ryan J Ollos (previous) (diff)

comment:6 by jhn@…, 12 years ago

Cc: jhn@… added

i'd like to see this too. i've read through FieldRefactoring and GenericTrac, and while they sound interesting, they are long-term. one of the best things about trac is its extensibility and customizability, and this enhancement could have so many different applications.

in our installation, we would use this for ranking of tickets. we use priority but it is not granular enough. our client ranks their top 20 tickets and we work our way down the list. we used the 00, 01, 02 workaround suggested by sid but we would prefer to have real numeric sorting.

this approach makes sense to me:
add a new type to TracTicketsCustomFields, "number" or "integer".
if a field is set to this type, just use a numeric sort on it with some simple error handling. the data could still be stored as a string in the backend so it seems that the changes would be limited.

comment:7 by anonymous, 12 years ago

recommend changing the summary from "Custom field sorts only as text" to "add numeric type to custom field types".

comment:8 by CraigBarber@…, 12 years ago

As a workaround, you can modify the ORDER BY clause in your reports with something similar to the following (for SQLite):

LEFT JOIN ticket_custom as some_custom_field ON some_custom_field.name='some_custom_field'
ORDER BY CASE WHEN some_custom_field.value ISNULL THEN 99999999 ELSE CAST(some_custom_field.value AS INTEGER) END

The CASE/ISNULL/99999999 sorts NULLs after all other defined values. You could just use CAST(…) if you don't care about NULL order.

comment:9 by Christian Boos, 11 years ago

Milestone: 1.0unscheduled

Milestone 1.0 deleted

comment:10 by achton@…, 11 years ago

If you only have numeric custom fields, another (dangerous) workaround is to alter the column type of the 'value' column in ticket_custom to float/integer. It may have adverse effects on the precision and visual output of the column content, but should allow proper numeric sorting. Use with care.


comment:11 by Christian Boos, 11 years ago

Keywords: fieldrefactoring added
Milestone: unschedulednext-major-0.1X

#9929 proposes to introduce pluggable sort orders, for version and milestone fields. Something we could fit into the FieldRefactoring spec and generalize to any field.

comment:12 by lkraav <leho@…>, 7 years ago

Cc: leho@… added

comment:13 by Ryan J Ollos, 6 years ago

Owner: Jonas Borgström removed

Modify Ticket

Change Properties
Set your email in Preferences
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.