Reverse sort order in Bugzilla
If you are a user of Bugzilla, you've probably run into the fact that Bugzilla does not allow you to sort in reverse order. When it's showing bugs, you can click on a column header to sort by that column. But the sort is always ascending (smallest result first, largest last) and clicking the same column again does not reverse the order of sort (as it does in many programs). This has frustrated me for a long time, but I've finally found a way around this problem in Bugzilla.
It turns out that when you click on a column to sort by it, Bugzilla stores the actual SQL for the sort in the URL (I won't even go into the security ramifications of something like this, but I suspect/hope they are doing something to mitigate them). For example, If you sort on the "ID" column in Bugzilla and you then look at the URL you'll see a parameter in the URL called "order", this is usually near the end of the URL. Here's an example snippet from the URL:
The thing to note here is that the value of "order" is "bugs.bug_id", which happens to be the table name/column (in the database) on which the sort is occurring. So far as I can tell, Bugzilla takes the value of the "order" parameter and injects it directly into the "order by" statement of the query used to create the results (hopefully with filtering). So, to reverse the sort order in this case, all you need to do is update the "order" parameter to include additional information to indicate a sort direction. In the case of SQL, this is done by adding " desc" to the sort criteria. By changing the above sort criteria to this:
Bugzilla will return the results sorted in the reverse order, which is descending. Note that the "%20" is just how you represent a space character in a URL.
With this knowledge, you can actually get Bugzilla to perform any type of sort that you'd like. First, in Bugzilla sort by the column(s) you want to include in your sort and look at the resulting URL to get the table and column name used (the format is table_name.column_name). You can then string together multiple sort criteria by using commas to separate them. For example, this URL snippet:
Would cause Bugzilla to sort first by ascending bug status, and then it would use the bug_id desc (which puts newer bugs near the top) for results that have the same status.
Once you get the feel for this, you can get Bugzilla to perform any type of sort that you'd like. But one thing you don't want to have to do is to hack the URL in Bugzilla every time you want to sort. To save yourself typing, you can save your search once you get the sort order correct and the sort order will be part of the saved search.
It turns out that when you click on a column to sort by it, Bugzilla stores the actual SQL for the sort in the URL (I won't even go into the security ramifications of something like this, but I suspect/hope they are doing something to mitigate them). For example, If you sort on the "ID" column in Bugzilla and you then look at the URL you'll see a parameter in the URL called "order", this is usually near the end of the URL. Here's an example snippet from the URL:
...&order=bugs.bug_id&...
The thing to note here is that the value of "order" is "bugs.bug_id", which happens to be the table name/column (in the database) on which the sort is occurring. So far as I can tell, Bugzilla takes the value of the "order" parameter and injects it directly into the "order by" statement of the query used to create the results (hopefully with filtering). So, to reverse the sort order in this case, all you need to do is update the "order" parameter to include additional information to indicate a sort direction. In the case of SQL, this is done by adding " desc" to the sort criteria. By changing the above sort criteria to this:
...&order=bugs.bug_id&20desc&...
Bugzilla will return the results sorted in the reverse order, which is descending. Note that the "%20" is just how you represent a space character in a URL.
With this knowledge, you can actually get Bugzilla to perform any type of sort that you'd like. First, in Bugzilla sort by the column(s) you want to include in your sort and look at the resulting URL to get the table and column name used (the format is table_name.column_name). You can then string together multiple sort criteria by using commas to separate them. For example, this URL snippet:
...&order=bugs.bug_status,bugs.bug_id%20desc&...
Would cause Bugzilla to sort first by ascending bug status, and then it would use the bug_id desc (which puts newer bugs near the top) for results that have the same status.
Once you get the feel for this, you can get Bugzilla to perform any type of sort that you'd like. But one thing you don't want to have to do is to hack the URL in Bugzilla every time you want to sort. To save yourself typing, you can save your search once you get the sort order correct and the sort order will be part of the saved search.
| Rating: | 100% positive, 6 total Votes |
| Categories: | Bugzilla hack programming debugging |
| Added: | on Sep 10, 2007 at 4:26 pm |
| Added By: | rlansky |


takes a while to recognise this... ;)