Dashboard > Atlassian Plugins > ... > Macros > text-sort
  Atlassian Plugins Log In | Sign Up   View a printable version of the current page.  
  text-sort

Added by david , last edited by David Peterson on Mar 11, 2008  (view change)
Labels: 

{text-sort}

Plugin: Reporting Plugin, from version 1.0

This will sort the results by the specified text key value.

Description

By default, empty values will be listed first, then the rest using ascending order.

Usage

{text-sort:prefix:key|mode=natural/exact|order=ascending/descending}

Parameters

Name Required Default Description
[default]/key
The key chain value to sort by.
order
ascending
May be 'ascending' or 'descending'.
mode
natural
The mode of text sort to used. May be one of:
  • natural - (default) Sorts in natural language order. It will order by symbols, then digits, then letters.
  • locale - Sorts in locale-sensitive alphanumeric order. E.g. "5", "10" and "1" will be sorted as "1", "10" and "5", because the first character of "10" is "1", which comes before "5". Punctuation order may vary depending on your locale. (Formerly called 'exact')
  • bitwise - Sorts in the order of the bit value of each character. This will mean that all upper-case characters are considered to be before any lower-case characters, as well as putting most international characters at the end of the sort order.
locale
@user
(Since 2.0.0) The locale to use when sorting text in either 'natural' or 'locale' mode. May be one of the following:
  • @user - (default) The current user's selected locale. Uses @global if no specific locale is selected by the user.
  • @global - The global default locale for Confluence.
  • @server - The server's default locale (may be different to @global)
  • xx_yy - A standard local value, such as "en_AU" or "de".

Recipes

See Also

Do you have more info on the "mode" parameter of this macro? It is in the example, but not the documentation. What is the difference between "natural" and "exact"?

Specifically I'm looking for sorting that I typcally call "alphanumeric" as opposed to "alphabetical"

This:

  • R4.7
  • R4.5.2
  • R4.5.1
  • R4.5
  • R4.4.4

As opposed to what the children macro gives me.

  • R4.7
  • R4.5
  • R4.5.2
  • R4.5.1
  • R4.4
  • R4.4.4

Thanks

You're right - I had missed that. I've added it above. I'm actually not sure which will give you what you're after in this case - it's possible that neither will work. It gets a bit tricky when two strings differ based on having extra characters - which is first? But try them both, see what happens.

Alas, you were right. Neither made any notable difference to the sorting.

Thanks for getting this info up so fast.

Hypothetically, we can add another sort mode to achieve what you're after. Probably the best approach would be to create a JIRA issue describing the desired behaviour. Even better would be to provide a sorting algorithm to achieve it. Even better still would be to attach a Comparator implementation which I can include in a future version.

Can we have multiple text-sort's in 1 content-reporter? I would like to sort on ObjectType, Space and Name.

My macro looks like:

{report-table}

{content-reporter:scope=@self|type=page}
  {expand-on:content:incoming links|as=link}
    {text-sort:link:destination > data:ObjectType|order=ascending}
  {expand-on}
{content-reporter}

{report-column:title=Object Type}{report-info:expanded:link > link:destination > data:ObjectType}{report-column}
{report-column:title=Space}{report-info:expanded:link > link:destination > content:space}{report-column}
{report-column:title=Incoming Link}{report-info:expanded:link|link=true}{report-column}
{report-column:title=Doc Status}{report-info:expanded:link > link:destination > data:DocStatus|render=wiki}{report-column}

{report-empty}
_No Incoming links available._
{report-empty}

{report-table}

Someone input on this question?

Thanks in advance!

Sorry for the delay - I've been on leave for the past month.

The answer is yes, you can have multiple sort parameters (text-sort, or otherwise). Reports will sort in the order you put them, from first to last. Each proceeding sort parameter is only checked if the previous one comes out as equal.

I have a report based on Scaffolding table data that is now working (thank you CustomWare), but I am having trouble getting a text sort to work based on the content of the table data. Basically within a scaffolding page I have a table of action items to report on higher up, but in that report I want to list the open items first. The report looks like this:

{report-table}

  {content-reporter:space=@self\|scope=Sample Meeting Notes}
    {expand-on:data:mn_action_items\|as=action_item}
      {text-sort:data:action_item > mn_action_item_status\|order=descending}
    {expand-on}
  {content-reporter}

  {report-column:title=Meeting Date}{report-info:expanded:item > data:mn_date \| format=dd-MMM-yyyy}{report-column}
  {report-column:title=Action Item}{report-info:expanded:action_item > mn_action_item}{report-column}
  {report-column:title=Status}{report-info:expanded:action_item > mn_action_item_status}{report-column}
  {report-column:title=Due Date}{report-info:expanded:action_item > mn_action_item_due_date\|format=dd-MMM-yyyy}{report-column}

{report-table}
 

The text-sort seems not to be functioning. I've tried numerous keychains: data:action_item > mn_action_item_status; item:action_item > mn_action_item_status; content:action_item > mn_action_item_status; action_item:mn_action_item_status; etc. It's likely I don't understand the possible keychain values to know how to construct the right sequence.

One additional question: if I want to sort all the action items across all pages by status first, then present first the open and then the closed items by a sort parameter in the page, is that possible?

Thanks very much! This is fourth template and the Scaffolding/Reporting combo is solving a lot of problems, but this one seems to be stumping me more than once. 

Hi Dennis,

Sort and filter macros inside an {expand-on} are relative to the thing being expanded on, so you don't need to specify the 'action_item' in the key chain there. Try this instead:

{expand-on:data:mn_action_items|as=action_item}
  {text-sort:mn_action_item_status|order=descending}
{expand-on}

This will only sort the action items within each page though, not overall across all pages being reported on. It's currently not possible to sort across all instances of an 'expanded' report. It's definitely a bit of a limitation. Feel free to create a feature request if you'd like to see it resolved in a future version of the plugin.

With regards to your additional question, I'm not exactly sure what you mean by 'by a sort parameter'. As in, a drop-down box the user can select which changes the sort order? If so, that's also currently not possible. It's on the todo list as well, but is unlikely to get added for a while yet...

Hi,

I report a list of all spaces and I try to sort them by space description, but this throws an error. Any idea?

{report-table}
{space-reporter}
    {text-sort:space:description}
{space-reporter}
 {report-column:title=Key}{report-info:space:key}{report-column}
 {report-column:title=Name (sorted)}h3.{report-info:space:name\|link=true}{report-column}
 {report-column:title=Description}{report-info:space:description > content:body\|render=wiki}{report-column}
 {report-column:title=Creation date}{report-info:space:creation date\|format=dd.MM.yyyy}{report-column}
 {report-column:title=Admin}{ops-spaceadmlink1}{report-info:space:key}{ops-spaceadmlink2}{report-column}
{report-table}


As noted in the Space Supplier page, the 'space:description' will give you a Content object, not a text/string object. Try adding the 'content:body' as you have already done in the Description column. Eg:

{text-sort:space:description > content:body}

Or, if you want to be terse:

{text-sort:description > body}
Copyright(c) CustomWare Asia Pacific Pty Ltd
Powered by Atlassian Confluence 2.7.3, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators