Bug 38436: Fix column visibility when bKohaColumnsUseNames is used
When the columns displayed in the table can vary (depending on sysprefs)
we use bKohaColumnsUseNames. This allows us to use the name of the
columns instead of there order number.
The code was totally wrong, and didn't retrieve the correct number.
A good example to confirm that is to add:
console.log("%s is at %s".format(this.columnname, used_id));
at the end of the `if ( use_names ) {` block of _dt_visibility.
If at least one column is hidden by default and cannot be toggled (and
so won't appear in the list of the columns of the "Column visibility" button),
there will be a shift.
This line was definitelly wrong:
var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector + ' th' );
We cannot rely on the order of the visible columns, we need to retrieve
the list of the columns using DT's api.
Now the columns are retrieved using their class names, and from DT's
api.
The code is way nicer and more inline with how we are supposed to play
with DT.
Look at those 2 lines to pass the list of columns to the colvis button:
let included_columns = table_settings.columns.filter(c => !c.cannot_be_toggled);
columns: included_columns.map(c => '.' + c.columnname).join(',')
Test plan:
Play intensively with the items table (detail.pl), but also with the
other tables not using bKohaColumnsUseNames (eg. patrons search)
You need to set column as hidden by default and/or cannot be toggled.
You need to play with the "Columns" button.
Note that you need to remove the localStorage keys starting with 'DataTables_'
to retrieve the visibility settings from what is defined in the admin area.
Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>