Bug 95520 - Sort column by color
Summary: Sort column by color
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium enhancement
Assignee: Samuel Mehrbrodt
URL:
Whiteboard: target:7.6.0 inReleaseNotes:7.6
Keywords:
: 89812 (view as bug list)
Depends on:
Blocks: Sorting
  Show dependency treegraph
 
Reported: 2015-11-02 12:11 UTC by Daniel Mustieles
Modified: 2025-08-21 12:12 UTC (History)
10 users (show)

See Also:
Crash report or crash signature:


Attachments
test case for Sort by color (62.36 KB, application/vnd.oasis.opendocument.spreadsheet)
2025-08-20 20:00 UTC, Olivier Hallot
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Mustieles 2015-11-02 12:11:33 UTC
Sorting columns by font/background color is quite useful several times, and having such sort criteria implemented would be great. There are some workarounds to get this, using functions, etc, but it's not easy-to-use, specially for newbies and non-technical users.

Google Drive has already added this same feature through a Chrome's plugin, and MS Office also has it, so LibreOffice should be aligned with them ;-)

Thanks in advance!
Comment 1 Daniel Mustieles 2015-11-02 12:14:38 UTC
Just a quick view about hot it works in Chrome

https://www.youtube.com/watch?v=9ZzpEoYUdsE
Comment 2 Cor Nouws 2015-11-02 18:52:08 UTC
Hi Daniel,

Nice idea. Let me set it to New.
I head in Google it's an addon. So something you / someone can make an extension for too?
Cheers - Cor
Comment 3 Daniel Mustieles 2015-11-03 10:01:59 UTC
Hi Cor,

I'm no t a developer, so cannot collaborate with code in this task, but maybe a workaround I used might help to implement it.

I had a spreadsheet with ~1000 rows, each of them highlighetd with a colour (4 colours used in total). I sorted  them in MS Excel by color and then, I added a new column to indicate the status, based in the color. Maybe having an internal code/number for each colour could help to implement the filter.

Thanks for all and best regards
Comment 4 William Gathoye 2019-05-22 12:49:58 UTC
Here is the code pointer given to me by Michael Meeks at the last FOSDEM hackfest.

sc/uiconfig/scalc/ui/sortdialog.ui
sc/source/ui/dbgui/sortdlg.cxx:    : SfxTabDialogController(pParent,
"modules/scalc/ui/sortdialog.ui", "SortDialog", pArgSet)

sc/source/ui/dbgui/tpsort.cxx -> does the sort (?)

@@ -125,6 +128,7 @@ bool ScSortParam::operator==( const ScSortParam&
rOther ) const

Compare vs. this commit:

commit b5f8b046008a27f1da58b934dbe61c0decf36612
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Date:   Mon Jan 22 17:47:04 2018 +0100

    tdf#98931 Add option to sort boundary image-only columns

    A similiar option exists for comments-only columns.
    If enabled, image-only columns are considered when sorting (and
selected).
Comment 5 William Gathoye 2019-05-22 12:50:54 UTC
I intend to work on this bug for the next Paris hackfest:
https://wiki.documentfoundation.org/Hackfest/Paris2019
Comment 6 Xisco Faulí 2019-09-26 10:26:16 UTC
Dear William Gathoye,
This bug has been in ASSIGNED status for more than 3 months without any
activity. Resetting it to NEW.
Please assigned it back to yourself if you're still working on this.
Comment 7 Samuel Mehrbrodt 2021-04-13 13:08:22 UTC
*** Bug 89812 has been marked as a duplicate of this bug. ***
Comment 8 SD 2023-01-01 01:59:00 UTC
Further to the solution of Filtering by Colour done by Samuel Mehrbrodt (https://bugs.documentfoundation.org/show_bug.cgi?id=76258) - can Sort by Colour, which was also mentioned in this dialog - be added as a tool?  This is a really commonly used Excel tool, which is a big miss for me. I've only just started using Libreoffice, so it would be a shame to have to switch to another program based on a seemingly simple missing feature.
Comment 9 Crusader 2023-04-25 23:49:51 UTC
As a big LO fan, I am disappointed to see this important issue languishing for >7 years.  This is a commonly used feature in other spreadsheets - and must be part of all respected spreadsheets.

I am respectfully requesting developers (I am not a developer) to work on this issue and bring this feature to LO.  I know of at least one case where lack of this feature resulted in the loss of a "convert."

LO does have the ability to "FILTER" by font color/background color, but there is no way to "SORT" by font color/background color.  Given the extensive usage of the sort function in spreadsheets, implementation of the sort feature will significantly increase respect for Calc and promote it as a valuable and respected spreadsheet.

Thanks in advance to everyone working to bring this feature to fruition.
Comment 10 Commit Notification 2023-05-08 06:14:59 UTC
Samuel Mehrbrodt committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/bb5e03681c576bc108c1e5c819957f1b34f80ca7

tdf#95520 Autofilter: Sort by color

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 11 Commit Notification 2023-05-09 17:26:46 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/efdbe4179d151899c8a9a9de8f5bc1660700b27d

tdf#95520: sc: Add UItest

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 12 Daniel Mustieles 2023-05-10 11:43:04 UTC
Many thanks for taking care of this.

I will test as soon as I can download and install new version.
Comment 13 Stéphane Guillou (stragu) 2023-09-25 13:59:05 UTC
Samuel, we are missing documentation for this feature: https://help.libreoffice.org/24.2/en-US/text/scalc/01/12040100.html

In my testing, it behaves as:
- whatever colour is selected is put first
- then all the other colours sorted by some constant colour sorting logic

Can you expand on the logic so it can be documented?
Comment 14 Samuel Mehrbrodt 2023-09-27 18:29:58 UTC
(In reply to Stéphane Guillou (stragu) from comment #13)
> Samuel, we are missing documentation for this feature:
> https://help.libreoffice.org/24.2/en-US/text/scalc/01/12040100.html
> 
> In my testing, it behaves as:
> - whatever colour is selected is put first

Correct.

> - then all the other colours sorted by some constant colour sorting logic
> 
> Can you expand on the logic so it can be documented?

The logic defined in include/tools/color.hxx is used, see https://opengrok.libreoffice.org/xref/core/include/tools/color.hxx?r=81994cb2#238-250

Basically, the colors are compared using an integer value (containing all three base colors).

Maybe there are better ways to compare/sort colors? Didn't put too much thought into the compare logic, since it was already there.
Comment 15 Stéphane Guillou (stragu) 2024-11-01 13:52:38 UTC
Tracking the gap in documentation in bug 163714.
Comment 16 Stéphane Guillou (stragu) 2024-11-01 13:53:41 UTC
And fix verified in 7.6 and:

Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 6bd9f1f93301756bdc6fa57911d163e9fa5ad313
CPU threads: 8; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: CL threaded
Comment 17 Olivier Hallot 2025-08-20 20:00:36 UTC
Created attachment 202416 [details]
test case  for Sort by color

The colors of the range are defined by conditional formatting
Comment 18 Olivier Hallot 2025-08-20 20:03:00 UTC
I beg to differ that this Sort by Color is ready.

The attached document shows different results from Excel 365 and LO 25.8.

Actually , both moves the colored row to the top but the rest of the rows are different.

The formatting of the cells are done by conditional formatting.
Comment 19 Xisco Faulí 2025-08-21 12:12:49 UTC
Hi Oliver,
Could you please create a follow-up ticket for the Excel vs Calc Comparison ?