![]() |
#1 |
Calibre Companion Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
|
New Custom Column definition for new sort
This might belong in the Calibre section, but I created it for CC based on ideas that others here gave me, and I am posting it here in case anyone else wants it for the same reason.
This started because people were talking about sorting by Author and then Series and then Title, but this was giving me sorts where the books without series were coming first and then all of the series. What I actually wanted was to have the titles and series mixed together alphabetically. So I created a column called Authors Works that gave the title of the book if the book wasn't part of a series and a series (index) if it was part of a series. The template is: program: first_non_empty( test(field('series'), strcat(field('series'), " (", field('series_index'), ")"), ""), field('title') ) I then added a custom grouping and now Author autosorts the way I want it to. |
![]() |
![]() |
![]() |
#2 | |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
Code:
program: first_non_empty( test( field('series'), strcat( field('series'), " (", field('series_index'), ")" ), "" ), field('title') ) ![]() I thought you might like to know, though, that you can use formatting here too, with finish_formatting() to apply prefix/suffix. The advantage here is that you can shape the series_index as demonstrated here to always return say, "07.50" for sorting purposes. It is also slightly more readable by condensing first_non_empty(test(stuff)) into ifempty(). Possible performance boost (minuscule) by not evaluating field('series') twice. (I am told you are a glutton for punishment, so you have to listen to me ramble about obscure template bits. ![]() Code:
program: ifempty( strcat( field('series'), finish_formatting( field('series_index'), "5.2f", " (", ")" ) ), field('title') ) Last edited by eschwartz; 08-11-2014 at 01:10 AM. |
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
@kaufman: as eschwartz said, nice.
![]() I assume that you are using the new custom column in a user-defined sort (Authors, #yourCol). You could do it all in the custom column, freeing a user-defined sort and also giving you the possibility to invert the sort. Using eschwartz's modification, the template would be: Code:
program: strcat( field('author_sort'), ':::', ifempty( strcat( field('series'), finish_formatting( field('series_index'), "5.2f", " (", ")" ) ), field('title') ) ) Last edited by chaley; 08-11-2014 at 03:49 AM. Reason: fix template to use author_sort instead of authors and to mention series_sort() |
![]() |
![]() |
![]() |
#4 | |
Calibre Companion Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
|
Thank you both for the suggestions.
Quote:
I have used both your suggestions and updated my definition to: Code:
program: strcat( field('author_sort'), " - ", ifempty( strcat( series_sort(), finish_formatting( field('series_index'), "5.2f", " (", ")" ) ), field('title') ) ) Off topic, but I wonder why its a field for author_sort but a function for series_sort. Thanks again to both of you for the improvements. |
|
![]() |
![]() |
![]() |
#5 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
It is because their isn't a series sort field in the database. The value is computed whenever it is needed. That is also why it cannot be edited in calibre's edit metadata dialogs.
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Calibre Companion Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
|
That's interesting. I wonder why that is. If the program can figure out how to do the series sort, why can't it figure out the other ones?
|
![]() |
![]() |
![]() |
#7 | |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
![]() The gory details are something like this: many fields can have different sort values. Especially when things get hairy with different languages. Also, some authors have odd names that don't follow the usual rules -- possibly they have multiple last names or whatever foreign concept I don't care about ![]() Why is series_sort different, would be a better question. I am not sure, except maybe it is assumed there will be no need for anyone to ever manually edit the series_sort? I cannot say I have heard of an example where it is necessary... |
|
![]() |
![]() |
![]() |
#8 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Purely historical. From time to time we get enhancement requests to add it as a first-class field, but no developer cares enough about it to do the considerable amount of work required.
|
![]() |
![]() |
![]() |
#9 | |
Calibre Companion Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
|
Quote:
My sorting was being messed up because I had an author who had 15 solo books and 1 book with another author. That 1 book was coming up at the top (because of the second author's name) rather than in the middle of the series that it is part of. |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Manual Sort or Sort by custom column | Dethmaul | Marvin | 2 | 04-28-2014 11:54 AM |
Custom column returns value based on value of another custom column? | calvin-c | Calibre | 3 | 09-14-2013 02:24 PM |
Custom yes/no column built from long text column | Philantrop | Library Management | 7 | 03-23-2013 07:44 PM |
how to move value(s) of tag column to a custom made column | zoorakhan | Library Management | 0 | 12-08-2012 03:53 AM |
Is it possible to sort a custom column like authors or title? | arspr | Library Management | 2 | 03-15-2011 04:44 PM |