Bug 30633

Summary: Move OPACHoldingsDefaultSortField to table settings configuration
Product: Koha Reporter: Katrin Fischer <katrin.fischer>
Component: OPACAssignee: Jonathan Druart <jonathan.druart>
Status: Pushed to stable --- QA Contact: Martin Renvoize (ashimema) <martin.renvoize>
Severity: normal    
Priority: P5 - low CC: aude.charillon, catrina, clemens.tubach, jonathan.druart, michaela.sieber, nick, raymund.delahunty
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=36640
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38080
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Restore the ability to define a default sort order for the holdings table at the OPAC. It replaces the system preference "OPACHoldingsDefaultSortField" that had been broken for a while. Note that its value is not migrated.
Version(s) released in:
25.11.00,25.05.06
Circulation function:
Bug Depends on: 41010, 41042, 16552, 16759, 29648    
Bug Blocks: 30634    
Attachments: Bug 30633: Prepare the ground
Bug 30633: Hide columns when needed
Bug 30633: Add default_sort_order to table settings
Bug 30633: Remove OPACHoldingsDefaultSortField
Bug 30633: Prepare the ground
Bug 30633: Hide columns when needed
Bug 30633: Add default_sort_order to table settings
Bug 30633: Remove OPACHoldingsDefaultSortField
Bug 30633: Default to 'Item type'
Bug 30633: Default to 'Current library' if item_level_itypes is off
Bug 30633: Prepare the ground
Bug 30633: Hide columns when needed
Bug 30633: Add default_sort_order to table settings
Bug 30633: Remove OPACHoldingsDefaultSortField
Bug 30633: Default to 'Item type'
Bug 30633: Default to 'Current library' if item_level_itypes is off
Bug 30633: Remove force_visibility flag
Bug 30633: Prepare the ground
Bug 30633: Hide columns when needed
Bug 30633: Add default_sort_order to table settings
Bug 30633: Remove OPACHoldingsDefaultSortField
Bug 30633: Default to 'Item type'
Bug 30633: Default to 'Current library' if item_level_itypes is off
Bug 30633: Remove force_visibility flag

Description Katrin Fischer 2022-04-27 16:44:53 UTC
Now that the sorting of a table can be defined in administration > table settings, we should move OPACHoldingsDefaultSortField there and remove the pref.
Comment 1 Catrina Berka 2023-02-16 19:03:08 UTC
Does 23.05 include the ability to sort the holdingst table? There is no sort capability on that table in 22.11 so the system preference is still needed.
Comment 2 Aude Charillon 2025-09-25 15:20:07 UTC
I believe making this happen would solve bug 35319 - Default sorting of the holdings table with OPACHoldingsDefaultSortField is broken?
Comment 3 Jonathan Druart 2025-10-14 09:28:25 UTC
Feature introduced by bug 16552, accidentally removed by bug 16759.
Comment 4 Jonathan Druart 2025-10-14 09:28:48 UTC
I can work on this if we get one tester and one QAer in advance for quick inclusion.
Comment 5 Jonathan Druart 2025-10-14 09:29:36 UTC
*** Bug 35319 has been marked as a duplicate of this bug. ***
Comment 6 Ray Delahunty 2025-10-14 09:50:04 UTC
We don't have server access but assuming this is testable in a sandbox, I'll try for the first signoff.
Comment 7 Jonathan Druart 2025-10-14 10:01:18 UTC
Created attachment 187856 [details] [review]
Bug 30633: Prepare the ground

Make the OPAC holdings table ready to use visibility based on
column's names.
Comment 8 Jonathan Druart 2025-10-14 10:01:20 UTC
Created attachment 187857 [details] [review]
Bug 30633: Hide columns when needed

We can use the force_visibility flag to hide column when they are empty
or should not be displayed because of syspref.
Comment 9 Jonathan Druart 2025-10-14 10:01:22 UTC
Created attachment 187858 [details] [review]
Bug 30633: Add default_sort_order to table settings

So we can pick a column from the table settings
http://localhost:8081/cgi-bin/koha/admin/columns_settings.pl#biblio-detail%7Choldingst
Comment 10 Jonathan Druart 2025-10-14 10:01:25 UTC
Created attachment 187859 [details] [review]
Bug 30633: Remove OPACHoldingsDefaultSortField

It's no longer needed
Comment 11 Jonathan Druart 2025-10-14 10:01:40 UTC
I am suggesting to remove OPACHoldingsDefaultSortField and have the default sort order option available for this table in the table settings.

With OpacLocationBranchToDisplay (introduced by bug 35006) it might improve the situation and answer the different needs.
Comment 12 Biblibre Sandboxes 2025-10-14 14:24:31 UTC
Created attachment 187886 [details] [review]
Bug 30633: Prepare the ground

Make the OPAC holdings table ready to use visibility based on
column's names.

Signed-off-by: Michaela <michaela.sieber@kit.edu>
Comment 13 Biblibre Sandboxes 2025-10-14 14:24:33 UTC
Created attachment 187887 [details] [review]
Bug 30633: Hide columns when needed

We can use the force_visibility flag to hide column when they are empty
or should not be displayed because of syspref.

Signed-off-by: Michaela <michaela.sieber@kit.edu>
Comment 14 Biblibre Sandboxes 2025-10-14 14:24:35 UTC
Created attachment 187888 [details] [review]
Bug 30633: Add default_sort_order to table settings

So we can pick a column from the table settings
http://localhost:8081/cgi-bin/koha/admin/columns_settings.pl#biblio-detail%7Choldingst

Signed-off-by: Michaela <michaela.sieber@kit.edu>
Comment 15 Biblibre Sandboxes 2025-10-14 14:24:38 UTC
Created attachment 187889 [details] [review]
Bug 30633: Remove OPACHoldingsDefaultSortField

It's no longer needed

Signed-off-by: Michaela <michaela.sieber@kit.edu>
Comment 16 Michaela Sieber 2025-10-14 14:35:42 UTC
Tested in Sandbox and additionally with ktd.

Testplan:

- search for a biblio with multiple items, e.g. biblionumber=211
- change the items so that they have different home libraries, current libraries, itemtypes, collections, and so on ...
- try different variations of sysprefs OPACHoldingsDefaultSortField and check that the sort order in the opac is always by item type
- apply patch
- Go to system preferences and verify that OPACHoldingsDefaultSortField does not exist any more
- Go to table settings and check the new drop down for default sort order
- try different variations of the default sort order settings and verify that the holdings table in the opac is sorted correctly
Comment 17 Martin Renvoize (ashimema) 2025-10-16 10:36:52 UTC
I'm happy to QA this, but we need someone to test and signoff on bug 41010 first to unblock this.
Comment 18 Jonathan Druart 2025-10-17 08:03:55 UTC
Michaela found a bug when testing this, I opened bug 41042.
Comment 19 Jonathan Druart 2025-10-17 12:49:17 UTC
Created attachment 188067 [details] [review]
Bug 30633: Default to 'Item type'
Comment 20 Jonathan Druart 2025-10-17 13:00:09 UTC
Created attachment 188068 [details] [review]
Bug 30633: Default to 'Current library' if item_level_itypes is off

We cannot set the default value in the yaml file dynamically.
This is not ideal but we are going to modify the default "Item type" if
item-level_itypes is off.
Comment 21 OpenFifth Sandboxes 2025-10-17 13:56:07 UTC
Created attachment 188069 [details] [review]
Bug 30633: Prepare the ground

Make the OPAC holdings table ready to use visibility based on
column's names.

Signed-off-by: Michaela <michaela.sieber@kit.edu>
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 22 OpenFifth Sandboxes 2025-10-17 13:56:09 UTC
Created attachment 188070 [details] [review]
Bug 30633: Hide columns when needed

We can use the force_visibility flag to hide column when they are empty
or should not be displayed because of syspref.

Signed-off-by: Michaela <michaela.sieber@kit.edu>
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 23 OpenFifth Sandboxes 2025-10-17 13:56:12 UTC
Created attachment 188071 [details] [review]
Bug 30633: Add default_sort_order to table settings

So we can pick a column from the table settings
http://localhost:8081/cgi-bin/koha/admin/columns_settings.pl#biblio-detail%7Choldingst

Signed-off-by: Michaela <michaela.sieber@kit.edu>
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 24 OpenFifth Sandboxes 2025-10-17 13:56:14 UTC
Created attachment 188072 [details] [review]
Bug 30633: Remove OPACHoldingsDefaultSortField

It's no longer needed

Signed-off-by: Michaela <michaela.sieber@kit.edu>
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 25 OpenFifth Sandboxes 2025-10-17 13:56:16 UTC
Created attachment 188073 [details] [review]
Bug 30633: Default to 'Item type'

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 26 OpenFifth Sandboxes 2025-10-17 13:56:18 UTC
Created attachment 188074 [details] [review]
Bug 30633: Default to 'Current library' if item_level_itypes is off

We cannot set the default value in the yaml file dynamically.
This is not ideal but we are going to modify the default "Item type" if
item-level_itypes is off.

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 27 Martin Renvoize (ashimema) 2025-10-20 13:18:14 UTC
Hmm,

1) OPAC datatables.js lacks force_visibility - The OPAC version doesn't have _dt_force_visibility() function like staff interface, so are we sure this is working for the OPAC?
2) Could we perhaps use the following for ordering instead of relying on indexes that may well change with future work:

  // Find column by name instead of index
  let current_location_col = holdingst_table_settings.columns.findIndex(
      c => c.columnname == 'item_current_location'
  );
  holdingst_table_settings.default_sort_order = current_location_col;

3) We need to make it clear in the release notes that the preference content is not migrated into the dt configs
Comment 28 Jonathan Druart 2025-10-21 07:05:08 UTC
Created attachment 188192 [details] [review]
Bug 30633: Remove force_visibility flag

It's not available at the OPAC, and we actually don't need it: we don't
save/restore DT's state.
Comment 29 Jonathan Druart 2025-10-21 07:05:50 UTC
(In reply to Martin Renvoize (ashimema) from comment #27)
> Hmm,
> 
> 1) OPAC datatables.js lacks force_visibility - The OPAC version doesn't have
> _dt_force_visibility() function like staff interface, so are we sure this is
> working for the OPAC?

Indeed, it's not needed at the OPAC. force_visibility has been introduced to force visiblity to restore DT's state. And it is not available for OPAC tables.

> 2) Could we perhaps use the following for ordering instead of relying on
> indexes that may well change with future work:
> 
>   // Find column by name instead of index
>   let current_location_col = holdingst_table_settings.columns.findIndex(
>       c => c.columnname == 'item_current_location'
>   );
>   holdingst_table_settings.default_sort_order = current_location_col;

Maybe, I don't know. We are storing/manipulating the index in the yaml and the DB for default_sort_order.
We could try and see if it's possible to remove the index completely and use the column's names everywhere, but that's for another day :)

> 3) We need to make it clear in the release notes that the preference content
> is not migrated into the dt configs

Added something to the release notes.
Comment 30 Michaela Sieber 2025-10-21 07:26:08 UTC
(In reply to Jonathan Druart from comment #29)
> (In reply to Martin Renvoize (ashimema) from comment #27)
> > 2) Could we perhaps use the following for ordering instead of relying on
> > indexes that may well change with future work:
> > 
> >   // Find column by name instead of index
> >   let current_location_col = holdingst_table_settings.columns.findIndex(
> >       c => c.columnname == 'item_current_location'
> >   );
> >   holdingst_table_settings.default_sort_order = current_location_col;
> 
> Maybe, I don't know. We are storing/manipulating the index in the yaml and
> the DB for default_sort_order.
> We could try and see if it's possible to remove the index completely and use
> the column's names everywhere, but that's for another day :)
> 

Hey Martin and Jonathan,

we would very much appreciate it if the column's names would be used. 
If you want to put this topic on the roadmap for 26.05, I'm happy to take care of testing it.
Comment 31 Martin Renvoize (ashimema) 2025-10-22 11:04:23 UTC
Created attachment 188286 [details] [review]
Bug 30633: Prepare the ground

Make the OPAC holdings table ready to use visibility based on
column's names.

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 32 Martin Renvoize (ashimema) 2025-10-22 11:04:26 UTC
Created attachment 188287 [details] [review]
Bug 30633: Hide columns when needed

We can use the force_visibility flag to hide column when they are empty
or should not be displayed because of syspref.

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 33 Martin Renvoize (ashimema) 2025-10-22 11:04:28 UTC
Created attachment 188288 [details] [review]
Bug 30633: Add default_sort_order to table settings

So we can pick a column from the table settings
http://localhost:8081/cgi-bin/koha/admin/columns_settings.pl#biblio-detail%7Choldingst

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 34 Martin Renvoize (ashimema) 2025-10-22 11:04:30 UTC
Created attachment 188289 [details] [review]
Bug 30633: Remove OPACHoldingsDefaultSortField

It's no longer needed

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 35 Martin Renvoize (ashimema) 2025-10-22 11:04:33 UTC
Created attachment 188290 [details] [review]
Bug 30633: Default to 'Item type'

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 36 Martin Renvoize (ashimema) 2025-10-22 11:04:35 UTC
Created attachment 188291 [details] [review]
Bug 30633: Default to 'Current library' if item_level_itypes is off

We cannot set the default value in the yaml file dynamically.
This is not ideal but we are going to modify the default "Item type" if
item-level_itypes is off.

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 37 Martin Renvoize (ashimema) 2025-10-22 11:05:51 UTC
Created attachment 188292 [details] [review]
Bug 30633: Remove force_visibility flag

It's not available at the OPAC, and we actually don't need it: we don't
save/restore DT's state.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 38 Martin Renvoize (ashimema) 2025-10-22 11:06:17 UTC
Thanks everyone, Passing QA
Comment 39 Lucas Gass (lukeg) 2025-10-24 13:58:51 UTC
Nice work everyone!

Pushed to main for 25.11
Comment 40 Paul Derscheid 2025-11-25 16:30:27 UTC
Nice work everyone!

Pushed to 25.05.x