go-pretty
go-pretty copied to clipboard
Transformer affects sorting
Describe the bug
I expected SortBy
to operate on the raw table data. However as soon as I set a transformer on the column I sort by, the sorting breaks.
Software (please complete the following information):
- OS: Linux
- GoLang Version 1.15.2
I'll look into this, but it'll be awesome if you could share a code snippet or simple example reproducing the bug.
Hey I figured what is happening. The sorting is done after converting every column to string and that includes the calls to the column transformers.
I'll see if I can provide an option to sort before conversion to string/transformation, but I can't commit to an ETA.
I cannot switch it to be the default behavior as it will not be backwards compatible to anyone expecting the sorting to be done after transformation.
I see, thanks for the feedback! Maybe we could add this as a setting to the SortBy
struct?
Hey! I finally got around to working on a solve for this when I realized that the "transformers" are invoked even before I convert the column contents into string. So there is no realistic way for me to compare and sort the contents before transformation since I cannot do <
check on two interface{}
objects.
Workaround I'd suggest: have an additional column with the original values and use that for sorting instead of the "transformed" column; but hide the column using ColumnConfig.Hidden.
Edit: OMG I just realized I replied after 2+ years. I apologize for the obscene delay.
No worries :smiley: I ended up using that workaround in duf
fwiw. It's not ideal, but I understand why it's problematic.