From 97ed70502c98bb0ed853dd4deeaa70b3a670cb1a Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 31 Aug 2020 20:42:11 +1000 Subject: [PATCH] Fix function which hides table columns based on saved selections --- .../static/script/inventree/tables.js | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/InvenTree/InvenTree/static/script/inventree/tables.js b/InvenTree/InvenTree/static/script/inventree/tables.js index 34f8824412..be0e1e6325 100644 --- a/InvenTree/InvenTree/static/script/inventree/tables.js +++ b/InvenTree/InvenTree/static/script/inventree/tables.js @@ -119,28 +119,6 @@ $.fn.inventreeTable = function(options) { inventreeSave(varName, size); }; - // Add a callback when the table is loaded - table.on('load-success.bs.table', function() { - - // Load visible column list - var visibleColumns = inventreeLoad(`table_columns_${tableName}`, null); - - // If a set of visible columns has been saved, load! - if (visibleColumns) { - var columns = visibleColumns.split(","); - - // Which columns are currently visible? - var visible = table.bootstrapTable('getVisibleColumns'); - - visible.forEach(function(column) { - // Visible field should *not* be visible! (hide it!) - if (!columns.includes(visible.field)) { - table.bootstrapTable('hideColumn', visible.field); - } - }); - } - }); - // Callback when a column is changed options.onColumnSwitch = function(field, checked) { console.log(`${field} -> ${checked}`); @@ -151,12 +129,34 @@ $.fn.inventreeTable = function(options) { // Save visible columns inventreeSave(`table_columns_${tableName}`, text); - - console.log('saving: ' + text); }; // Standard options for all tables table.bootstrapTable(options); + + // Load visible column list from memory + // Load visible column list + var visibleColumns = inventreeLoad(`table_columns_${tableName}`, null); + + // If a set of visible columns has been saved, load! + if (visibleColumns) { + var columns = visibleColumns.split(","); + + // Which columns are currently visible? + var visible = table.bootstrapTable('getVisibleColumns'); + + if (visible) { + visible.forEach(function(column) { + + // Visible field should *not* be visible! (hide it!) + if (column.switchable && !columns.includes(column.field)) { + table.bootstrapTable('hideColumn', column.field); + } + }); + } else { + console.log('Could not get list of visible columns!'); + } + } } function customGroupSorter(sortName, sortOrder, sortData) {