TableOfContents

Original Table

First

Second

Third

A

2,000,000

zebra

C

1

123

b

2

word

d

30

word

A

2

Wordy

B

4.2

23

A

2

word

Column 1 No Sort

[[SortBy(SortByTest, 1, 1, nosort)]]

<<SortBy(SortByTest, 1, 1, nosort)>>

This simply includes the first table on the source page at this point in the page containing the macro. Rows are in the same order as the original table.

Column 1 Reverse No Sort

[[SortBy(SortByTest, 1, 1, reversenosort)]]

SortBy(SortByTest, 1, 1, reversenosort)

Similar to the previous example, but now all rows except the one header row are in reverse order.

Column 1 Alphabetical

[[SortBy(SortByTest, 1, 1, alpha)]]

SortBy(SortByTest, 1, 1, alpha)

In alphabetical order all uppercase letters are sorted before lowercase letters.

Column 1 Reverse Alphabetical

[[SortBy(SortByTest, 1, 1, reversealpha)]]

SortBy(SortByTest, 1, 1, reversealpha)

Prepending 'reverse' to the sort-type changes the order from ascending to descending.

Column 1 Case-Insensitive

[[SortBy(SortByTest, 1, 1, nocase)]]

SortBy(SortByTest, 1, 1, nocase)

Now 'B' and 'b' are considered equal, and are presented in the order they appear in the original table.

Column 2 Numerical

[[SortBy(SortByTest, 1, 2, number)]]

SortBy(SortByTest, 1, 2, number)

As you would expect, 30 comes before 2,000,000. Commas are ignored for sorting. Integers and floating point can both be used, and they sort correctly.

Column 2 Alphabetical

[[SortBy(SortByTest, 1, 2, alpha)]]

SortBy(SortByTest, 1, 2, alpha)

In 'alphabetical' order, 2 comes before 3, so 2,000,000 sorts before 30.

Column 2 Reverse Numerical

[[SortBy(SortByTest, 1, 2, reversenumber)]]

SortBy(SortByTest, 1, 2, reversenumber)

Again, prepending 'reverse' to the sort-type changes the order from ascending to descending.

Column 3 Alphabetical

[[SortBy(SortByTest, 1, 3, alpha)]]

SortBy(SortByTest, 1, 3, alpha)

Wiki formatting is ignored, and the sort is stable. The variations of 'word' are simply listed in the same order as they appear in the original table.

Column 3 Numerical

[[SortBy(SortByTest, 1, 3, number)]]

SortBy(SortByTest, 1, 3, number)

Now 23 comes before 123, and non-numeric values are sorted in alphabetical order as above.

Column 1 Alphabetical, Column 2 Numerical, Column 3 Alphabetical

[[SortBy(SortByTest, 1, 1, alpha, 2, number, 3, alpha)]]

SortBy(SortByTest, 1, 1, alpha, 2, number, 3, alpha)

The main sort is on column 1, but within the duplicate 'A's the 2's and 2,000,000 are sorted, and within the 2's the values in column 3 are in case-sensitive alphabetical order.

Column 1 Case-Insensitive, Column 2 Numerical, Column 3 Case-Insensitive

[[SortBy(SortByTest, 1, 1, nocase, 2, number, 3, nocase)]]

SortBy(SortByTest, 1, 1, nocase, 2, number, 3, nocase)

The main sort is still on column 1, but within the case-insensitive duplicate 'b's the values in column 2 are in numerical order. Also, within the duplicate A-2 rows, column 3 is case-insensitive, so now Wordy follows word.

Zero Header Rows, Case-Insensitive Sort on Column 1

[[SortBy(SortByTest, 0, 1, nocase)]]

SortBy(SortByTest, 0, 1, nocase)

The first row is sorted along with all the other rows.

Three Header Rows, Case-Insensitive Sort on Column 1

[[SortBy(SortByTest, 3, 1, nocase)]]

SortBy(SortByTest, 3, 1, nocase)

The first three rows are not sorted along with all the other rows.

Invalid Argument Examples

SortBy(NonExistentPage, 1, 1, nocase)

SortBy(SortByTest, 1, 1)

SortBy(SortByTest, x, 1, alpha)

SortBy(SortByTest, 1, x, alpha)

SortBy(SortByTest, -1, 1, alpha)

SortBy(SortByTest, 10, 1, alpha)

SortBy(SortByTest, 1, 0, alpha)

SortBy(SortByTest, 1, 10, alpha)

SortBy(SortByTest, 1, 1, x)

SortBy(SortByTest, 1, 1, alpha, 1)