Bug 18148 - Make list of lists in OPAC sortable
Summary: Make list of lists in OPAC sortable
Status: Passed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: Main
Hardware: All All
: P2 enhancement
Assignee: David Cook
QA Contact: Laura Escamilla
URL:
Keywords:
Depends on: 28965
Blocks:
  Show dependency treegraph
 
Reported: 2017-02-21 17:15 UTC by Alexandre
Modified: 2025-10-30 22:57 UTC (History)
15 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Crowdfunding goal: 0
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 18148: Make list of lists in OPAC sortable (9.11 KB, patch)
2025-10-27 05:37 UTC, David Cook
Details | Diff | Splinter Review
Bug 18148: Add unit tests (3.07 KB, patch)
2025-10-27 05:37 UTC, David Cook
Details | Diff | Splinter Review
Bug 18148: Make list of lists in OPAC sortable (9.16 KB, patch)
2025-10-27 11:32 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 18148: Add unit tests (3.12 KB, patch)
2025-10-27 11:32 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 18148: Make list of lists in OPAC sortable (9.23 KB, patch)
2025-10-30 12:44 UTC, Laura Escamilla
Details | Diff | Splinter Review
Bug 18148: Add unit tests (3.19 KB, patch)
2025-10-30 12:44 UTC, Laura Escamilla
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandre 2017-02-21 17:15:50 UTC
Hi,

Some librarians ask us to have public lists in chronological order rather than in alphabetical order because some schools will have to kept them there for a long time. This results in a big list with many pages on which is more difficult to find the good list.

1) Go in an OPAC interface
2) Go to "Lists" normally in top left corner
3) A small list appears from the top of the screen, observe that this list is by modification date (not alphabetical order)
4) Clic then on public lists
5) Observe that all lists created are in alphabetical order and their order cannot be changed

We are wondering if it's possible to have some sorting options for the results list like in the staff client interface. There, you can change for chronological (modification or creation date) but also by owner order.

Thanks for helping us,

Alexandre from CCSR
Comment 1 Katrin Fischer 2020-04-19 11:02:01 UTC
I just checked, the table is not sortable, but it would be nice to have.
Comment 2 Owen Leonard 2020-04-20 12:39:47 UTC
The list of lists in the OPAC is paginated server-side, so adding sorting would require one of these methods:

1. Add sorting to the query, including handling of ascending and descending and the ability to order by the number of titles on the list.

2. Remove the server-side pagination and use DataTables to sort and paginate the all the results client-side. This would be adequate only if it isn't expected that there might be a very large number of lists.

3. Remove the server-side pagination and re-implement the table with an AJAX datasource, doing AJAX pagination.
Comment 3 Katrin Fischer 2020-04-28 19:45:28 UTC
I think 1) might be easiest, but I think we will keep adding new sort requests for every columsn etc and it seems a bit non-standard these days.

I am not sure how many entries some lists have - I haven't seen a really really long one, but it could happen... so maybe 3) would be best?

Adding tcohen as I think handling big table data server side is something he has been working on for acquisitions in order to fix performance issues.
Comment 4 Tomás Cohen Arazi (tcohen) 2020-04-28 20:00:33 UTC
(In reply to Owen Leonard from comment #2)
> The list of lists in the OPAC is paginated server-side, so adding sorting
> would require one of these methods:
> 
> 1. Add sorting to the query, including handling of ascending and descending
> and the ability to order by the number of titles on the list.
> 
> 2. Remove the server-side pagination and use DataTables to sort and paginate
> the all the results client-side. This would be adequate only if it isn't
> expected that there might be a very large number of lists.
> 
> 3. Remove the server-side pagination and re-implement the table with an AJAX
> datasource, doing AJAX pagination.

4. Add an API route for this, and use the features we've recently added (specially bug 24561). It would make sorting by any column just trivial.
Comment 5 Jason Robb 2020-11-16 21:53:16 UTC
We currently have a metric ton of public lists.

Having a way to sort and filter the list of lists in the OPAC like we can in the staff client would be incredibly beneficial to our OPAC users.
Comment 6 Sally 2021-09-06 16:31:30 UTC
We don't have a metric tonne, because we review and remove ours periodically, but it would be brilliant to have lists be sortable on the OPAC.

It'd be even better if the staff client could control the default order (e.g. date added, date desc).  

We don't have a preference over 1, 2, 3 or 4 - they're all workable solutions.  

2 might be nice for consistency; I think the Charges table uses DataTables on the OPAC?  We can always target a DataTable with jQuery to set the default sort.
Comment 7 Tomás Cohen Arazi (tcohen) 2021-09-07 16:14:11 UTC
(In reply to Sally from comment #6)
> 2 might be nice for consistency; I think the Charges table uses DataTables
> on the OPAC?  We can always target a DataTable with jQuery to set the
> default sort.

Truth is, 4 implies 2. i.e. implement using DataTables, but against the API instead of a custom script in svc.

Let's do it :-D
Comment 8 Sally 2021-10-06 08:33:47 UTC
Ah brilliant - sounds like a great approach!
Comment 9 Marjorie Barry-Vila 2021-11-23 16:20:10 UTC
+1
Comment 10 Barbara Johnson 2022-02-17 17:05:53 UTC
Our library would like to be able to sort the list of lists alphabetically and by date.  It would also be nice if there was a way to bump a specific list (such as a seasonal list or hot top) to the top of the list of lists in order to highlight it for patrons.
Comment 11 Sally 2022-07-27 12:21:56 UTC
We're still interested in this development.
Comment 12 Donna 2022-08-15 17:36:50 UTC
We've recently had more libraries asking for options in how the lists display in the OPAC.  Ideally, the option to order them like news items are handled using "display in position" would be best.
Comment 13 Katrin Fischer 2022-08-15 17:47:01 UTC
(In reply to Donna from comment #12)
> We've recently had more libraries asking for options in how the lists
> display in the OPAC.  Ideally, the option to order them like news items are
> handled using "display in position" would be best.

I think it makes it a little hard to order/reorder if you have a lot of lists. Maybe we could integrate something like drag&drop sorting to make this easier to handle.
Comment 14 David Cook 2023-03-24 05:25:14 UTC
Had a library ask for this today, but it sounds like the community is a bit stuck on how to proceed?

For what it's worth, on the server side, we're using DataTables. We may as well do it on the OPAC too.
Comment 15 Fiona Fogden 2023-06-09 08:56:41 UTC
PLEASE can the list of lists at the very least be sortable alphabetically? Sorted by creation or some other random order really makes it a challenge to promote the lists and the only workaround is to create links to the lists manually in alpha order in an html page so defeating the otherwise brilliant idea of the lists. 
This is coming from a Koha user & Librarian in a membership organisation. 

Thank you, Fiona, RICS.
Comment 16 David Cook 2023-11-22 05:51:03 UTC
(In reply to Fiona Fogden from comment #15)
> PLEASE can the list of lists at the very least be sortable alphabetically?
> Sorted by creation or some other random order really makes it a challenge to
> promote the lists and the only workaround is to create links to the lists
> manually in alpha order in an html page so defeating the otherwise brilliant
> idea of the lists. 
> This is coming from a Koha user & Librarian in a membership organisation. 
> 
> Thank you, Fiona, RICS.

It looks like the list of lists is sorted alphabetically in the OPAC:

http://localhost:8080/cgi-bin/koha/opac-shelves.pl?op=list&public=0
http://localhost:8080/cgi-bin/koha/opac-shelves.pl?op=list&public=1

Although in the "Lists" dropdown it seems to be sorted by newest to oldest. 

Funnily enough the list of lists in the staff interface seems to sort by oldest to newest:

http://localhost:8081/cgi-bin/koha/virtualshelves/shelves.pl
Comment 17 David Cook 2023-11-22 06:03:27 UTC
I do want to look at this before the end of the year.

Reminder to myself and others that the DataTable wrapper around the REST API comes from bug 24561

I'm not sure this feature is currently used in OPAC at all, but bug 24561 appears to have added it for OPAC so fingers crossed that it works.
Comment 18 David Cook 2023-11-22 06:06:31 UTC
Not quite ready to take this one as Assignee yet. At the moment, I'm trying to still figure out how much work this is going to be...
Comment 19 Fiona Fogden 2023-11-22 09:29:16 UTC
Thank you @david cook. I am not technical but happy to help with testing if I can remember how to do that from my recent PTFS customer forum session!
Comment 20 Martin Renvoize (ashimema) 2025-01-06 13:50:14 UTC
Are you still intending to look into this David?
Comment 21 David Cook 2025-01-06 22:20:43 UTC
(In reply to Martin Renvoize (ashimema) from comment #20)
> Are you still intending to look into this David?

It's on my TODO list (as a low priority), but I'm not as adept with the API-driven DataTables as others I think, so if someone else wants to do it I'd be more than happy for them to do it.

I had hoped to have time in December 2024 to do it, but other things took priority. 

But if no one else does it, eventually I plan to do it.
Comment 22 David Cook 2025-09-29 07:02:54 UTC
(In reply to David Cook from comment #21)
> But if no one else does it, eventually I plan to do it.

It seems like eventually might have come around. Hoping to take a deeper look at this.

If I understand the API correctly, it looks like it would work like this:

Private lists:
/api/v1/public/lists?only_mine=true

Public lists:
/api/v1/public/lists?only_public=true

As I say that... it looks like there might be a discrepancy between the API and the existing table... and that's the "Contents" column. The /public/lists endpoint doesn't provide this information.
Comment 23 David Cook 2025-09-29 07:08:27 UTC
(In reply to David Cook from comment #22)
> As I say that... it looks like there might be a discrepancy between the API
> and the existing table... and that's the "Contents" column. The
> /public/lists endpoint doesn't provide this information.

So the next step might be to add the contents count to /public/lists... as I could see people complaining if they had an API driven table without it.

Of course, I could work on this in parallel to get the basics together and just add in that column a the end...
Comment 24 David Cook 2025-09-30 06:01:06 UTC
(In reply to David Cook from comment #23)
> So the next step might be to add the contents count to /public/lists... as I
> could see people complaining if they had an API driven table without it.
> 
> Of course, I could work on this in parallel to get the basics together and
> just add in that column a the end...

Actually... there's more than just the contents count. There's a number of authorization checks that need to be done per list for things like the "Edit", "Delete", and "Share" buttons.
Comment 25 David Cook 2025-10-21 04:20:08 UTC
(In reply to Tomás Cohen Arazi (tcohen) from comment #4)
> (In reply to Owen Leonard from comment #2)
> > The list of lists in the OPAC is paginated server-side, so adding sorting
> > would require one of these methods:
> > 
> > 1. Add sorting to the query, including handling of ascending and descending
> > and the ability to order by the number of titles on the list.
> > 
> > 2. Remove the server-side pagination and use DataTables to sort and paginate
> > the all the results client-side. This would be adequate only if it isn't
> > expected that there might be a very large number of lists.
> > 
> > 3. Remove the server-side pagination and re-implement the table with an AJAX
> > datasource, doing AJAX pagination.
> 
> 4. Add an API route for this, and use the features we've recently added
> (specially bug 24561). It would make sorting by any column just trivial.

After doing some investigating, I think that option 1 (or rather option 1 with reduced functionality) might be the only feasible one.

Option 3/4 would be great but the current API endpoints added aren't sufficient for this purpose, so they'd either need to be refactored or new API endpoints added. There's a bit of UI complexity that's unique to lists.
Comment 26 David Cook 2025-10-21 04:25:50 UTC
(In reply to David Cook from comment #25)
> After doing some investigating, I think that option 1 (or rather option 1
> with reduced functionality) might be the only feasible one.
> 
> Option 3/4 would be great but the current API endpoints added aren't
> sufficient for this purpose, so they'd either need to be refactored or new
> API endpoints added. There's a bit of UI complexity that's unique to lists.

That said, I don't think we have any HTML or CSS to do this, as everything has been moved to DataTables, so we might need to create something just for Lists, which seems... suboptimal.
Comment 27 David Cook 2025-10-24 04:53:18 UTC
Curious if Owen has any ideas for how this could be styled for a server-side sort without re-inventing the wheel...
Comment 28 David Cook 2025-10-27 03:11:01 UTC
Actually, I think that I've had a brain wave. 

In the search results (/cgi-bin/koha/opac-search.pl?idx=&q=test&weight_search=1), there is a dropdown menu above the results that typically says "Relevance" but lets you choose alternate sorts. 

So we have a precedent that we can work with.

I think that I've actually figured out a way to get them to both display nicely on one line of the toolbar... 

I think it's a very practical solution.
Comment 29 David Cook 2025-10-27 03:35:23 UTC
(In reply to David Cook from comment #28)
> Actually, I think that I've had a brain wave. 
> 
> In the search results
> (/cgi-bin/koha/opac-search.pl?idx=&q=test&weight_search=1), there is a
> dropdown menu above the results that typically says "Relevance" but lets you
> choose alternate sorts. 
> 
> So we have a precedent that we can work with.
> 
> I think that I've actually figured out a way to get them to both display
> nicely on one line of the toolbar... 
> 
> I think it's a very practical solution.

Actually... it looks like there's a Sort option for the toolbar on per shelf basis (e.g. /cgi-bin/koha/opac-shelves.pl?op=view&shelfnumber=4)

--

Some thinking to do on the styling perhaps but yeah... I think that's something I can work with...
Comment 30 David Cook 2025-10-27 05:37:28 UTC
Created attachment 188459 [details] [review]
Bug 18148: Make list of lists in OPAC sortable

This patch adds sorting to lists of lists in the OPAC.

The mechanism used here for op=list is similar to the one
used in op=view, so it's stylistically and functionally
consistent with the rest of the Lists module in the OPAC.

Test plan:
0. Apply the patch and restart Plack (ie koha-plack --restart kohadev)
1. Create 20+ public lists and 20+ private lists for a particular user
you control (try to use names that range throughout the alphabet)
2. Using SQL, update the Modification date for at least 1 public
list and 1 private list
3. As an anonymous (ie not logged in user), go to
/cgi-bin/koha/opac-shelves.pl?op=list&public=0
4. Note you cannot see any lists
5. Go to http://localhost:8080/cgi-bin/koha/opac-shelves.pl?op=list&public=1
6, Note you can see public lists with a toolbar with the button "Sort"
below the alert "Log in to create a new list"
7. Using the "Sort" option, try out all the different sort options
for default, "List name", and "Modification date"
8. After sorting, try paging through the list of lists. You should
note that the sorting is retained through the paging.
9. prove t/db_dependent/Virtualshelves.t
10. Celebrate!
Comment 31 David Cook 2025-10-27 05:37:32 UTC
Created attachment 188460 [details] [review]
Bug 18148: Add unit tests
Comment 32 Owen Leonard 2025-10-27 11:32:00 UTC
Created attachment 188470 [details] [review]
Bug 18148: Make list of lists in OPAC sortable

This patch adds sorting to lists of lists in the OPAC.

The mechanism used here for op=list is similar to the one
used in op=view, so it's stylistically and functionally
consistent with the rest of the Lists module in the OPAC.

Test plan:
0. Apply the patch and restart Plack (ie koha-plack --restart kohadev)
1. Create 20+ public lists and 20+ private lists for a particular user
you control (try to use names that range throughout the alphabet)
2. Using SQL, update the Modification date for at least 1 public
list and 1 private list
3. As an anonymous (ie not logged in user), go to
/cgi-bin/koha/opac-shelves.pl?op=list&public=0
4. Note you cannot see any lists
5. Go to http://localhost:8080/cgi-bin/koha/opac-shelves.pl?op=list&public=1
6, Note you can see public lists with a toolbar with the button "Sort"
below the alert "Log in to create a new list"
7. Using the "Sort" option, try out all the different sort options
for default, "List name", and "Modification date"
8. After sorting, try paging through the list of lists. You should
note that the sorting is retained through the paging.
9. prove t/db_dependent/Virtualshelves.t
10. Celebrate!

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 33 Owen Leonard 2025-10-27 11:32:03 UTC
Created attachment 188471 [details] [review]
Bug 18148: Add unit tests

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 34 David Cook 2025-10-27 22:48:50 UTC
You're a legend, Owen. Thanks heaps!
Comment 35 Laura Escamilla 2025-10-30 12:44:53 UTC
Created attachment 188635 [details] [review]
Bug 18148: Make list of lists in OPAC sortable

This patch adds sorting to lists of lists in the OPAC.

The mechanism used here for op=list is similar to the one
used in op=view, so it's stylistically and functionally
consistent with the rest of the Lists module in the OPAC.

Test plan:
0. Apply the patch and restart Plack (ie koha-plack --restart kohadev)
1. Create 20+ public lists and 20+ private lists for a particular user
you control (try to use names that range throughout the alphabet)
2. Using SQL, update the Modification date for at least 1 public
list and 1 private list
3. As an anonymous (ie not logged in user), go to
/cgi-bin/koha/opac-shelves.pl?op=list&public=0
4. Note you cannot see any lists
5. Go to http://localhost:8080/cgi-bin/koha/opac-shelves.pl?op=list&public=1
6, Note you can see public lists with a toolbar with the button "Sort"
below the alert "Log in to create a new list"
7. Using the "Sort" option, try out all the different sort options
for default, "List name", and "Modification date"
8. After sorting, try paging through the list of lists. You should
note that the sorting is retained through the paging.
9. prove t/db_dependent/Virtualshelves.t
10. Celebrate!

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Laura_Escamilla <laura.escamilla@bywatersolutions.com>
Comment 36 Laura Escamilla 2025-10-30 12:44:56 UTC
Created attachment 188636 [details] [review]
Bug 18148: Add unit tests

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Laura_Escamilla <laura.escamilla@bywatersolutions.com>
Comment 37 David Cook 2025-10-30 22:57:20 UTC
You're also a legend, Laura!

This has been on my TODO list for nearly 3 years, so I'm very excited at the idea of it being completed.