Bug 94660 - ORDERING with Unicode order is not respected (sort dialogue and autofilter)
Summary: ORDERING with Unicode order is not respected (sort dialogue and autofilter)
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
4.2.2.1 release
Hardware: Other All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: AutoFilter Sorting
  Show dependency treegraph
 
Reported: 2015-10-01 09:15 UTC by PBrockmann
Modified: 2023-05-07 17:29 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description PBrockmann 2015-10-01 09:15:29 UTC
I have a problem with sorting when I use autofilter ascending with Calc. It gives me something different from the order given by a unix ls command (Unicode order):

> ls -1
aaa2004
aaa_2005
aaa_2006

Calc with an autofilter set on ascending order gives me:

aaa_2005
aaa_2006
aaa2004

Reported at:
https://ask.libreoffice.org/en/question/58253/autofilter-with-ascending-gives-a-different-order-from-unix/
Comment 1 Buovjaga 2015-10-02 16:32:15 UTC
Setting to NEW as A. Kemp reproduced in the AskLibO page.
Comment 2 QA Administrators 2016-11-08 10:33:25 UTC Comment hidden (obsolete)
Comment 3 QA Administrators 2019-12-03 14:48:22 UTC Comment hidden (obsolete)
Comment 4 Stéphane Guillou (stragu) 2021-06-14 13:55:57 UTC
Reproduced in:

Version: 7.2.0.0.alpha1+ / LibreOffice Community
Build ID: bb54d6d8241a06a6772052b77b67d6a4f686426c
CPU threads: 8; OS: Linux 4.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
TinderBox: Linux-rpm_deb-x86_64@86-TDF, Branch:master, Time: 2021-06-11_20:14:38
Calc: threaded
Comment 5 Robert Lacroix 2023-04-18 03:01:55 UTC
There is a bug here, but it's not what the OP thinks it is.
The bug is: autofilter overwrites the sort range's descriptor.

The OP wants the natural sort order, but that's not available through autofilter. So we sort the range with options and then add Autofilter. The problem is that Autofilter, when actually applied, overwrites the sort order option set in the sort range's descriptor.

1) Open a new Calc document and enter the OP's data into a column of cells along with a heading row of "data", but we scramble the data a bit to confirm that the sort is happening.
Our cell contents are:
data
aaa2004
aaa_2006
aaa_2005

2) Select the range including the heading and sort it with options:
2a) Select the range including the title
2b) Choose Data menu > Sort...
2c) Choose Sort dialog Options tab
2d) Check "Range includes column labels"
2e) Check "Enable natural sort"
2f) Click OK

The data is now sorted as the OP wants. Our cell contents are:
data
aaa2004
aaa_2005
aaa_2006

3) With the range still selected, choose Data menu > Autofilter
Autofilter sees that the range has a column heading set by the sort range's descriptor and does not ask whether to use the first row as a heading. This is good. The range's heading cell now acquires the Autofilter dropdown menu button, but nothing will happen to the data until the Autofilter option is exercised, which we will do in step 5.

4) With the range still selected, confirm that sort options are still set.
2a) Choose Data menu > Sort...
2b) Choose Sort dialog Options tab
2c) See that the column labels and natural sort options are still checked
2d) Click Cancel

5) Sort the range using the Autofilter's dropdown menu button in the heading.
5a) Click the downward pointing triangle in the heading cell
5b) Click Sort Ascending

Notice that the data is now sorted as the OP's complains, not the natural order.

6) With the heading row still selected, verify sort options once again.
6a) Choose Data menu > Sort...
6b) Choose Sort dialog Options tab
6c) See that the column label is still checked but the natural sort is now unchecked.
2d) Click Cancel

Step 6 shows that the Autofilter sorting action overwrites the sort descriptor. The Sort Ascending and Sort Descending UI buttons and corresponding menu options are even more egregious, wiping out the entire sort descriptor including the column heading. Is this by design? I think not.

As far as the default sort order, I find no fault in LO Calc's choice.

Unicode Technical Standard #10 UNICODE COLLATION ALGORITHM
https://www.unicode.org/reports/tr10/

declares as the basic principle:

"The position of characters in the Unicode code charts does not specify their sort order."

The meaning of "Unicode order" is thus utterly ambiguous because code points collate in different orders for different languages. However, taking the cue of "unix ls" as the OP's desired sort order, the "Enable natural sort" option should be selected by the OP. The default sort order used by LO is in fact the start of the Unicode code set, where the first 127 characters copies the 7-bit ASCII code: punctuation precedes digits which precedes alphabetic characters.