From 121d68aa87c691bdc40121ca7bdcb159358fc297 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 21 Oct 2022 17:05:10 +1100 Subject: [PATCH] Bom table load fix (#3826) * Optimize loading of BOM table - Do not use updateByUniqueId (inefficient!) - Instead, process and reload the entire table * Optimize part parameter table * Revert testing change * javascript linting --- InvenTree/templates/js/translated/bom.js | 15 ++++++++++----- InvenTree/templates/js/translated/filters.js | 2 +- InvenTree/templates/js/translated/part.js | 6 ++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js index 5380afae649b..1fe074639678 100644 --- a/InvenTree/templates/js/translated/bom.js +++ b/InvenTree/templates/js/translated/bom.js @@ -1308,15 +1308,20 @@ function loadBomTable(table, options={}) { var data = table.bootstrapTable('getData'); - for (var idx = 0; idx < data.length; idx++) { - var row = data[idx]; + var update_required = false; - if (!row.parentId) { - row.parentId = parent_id; + for (var idx = 0; idx < data.length; idx++) { - table.bootstrapTable('updateByUniqueId', row.pk, row, true); + if (!data[idx].parentId) { + data[idx].parentId = parent_id; + update_required = true; } } + + // Re-load the table back data + if (update_required) { + table.bootstrapTable('load', data); + } }, onLoadSuccess: function(data) { diff --git a/InvenTree/templates/js/translated/filters.js b/InvenTree/templates/js/translated/filters.js index 349b3028eda8..d2edcaf5fe2b 100644 --- a/InvenTree/templates/js/translated/filters.js +++ b/InvenTree/templates/js/translated/filters.js @@ -324,7 +324,7 @@ function setupFilterList(tableKey, table, target, options={}) { // Callback for reloading the table element.find(`#reload-${tableKey}`).click(function() { - $(table).bootstrapTable('refresh'); + reloadTableFilters(table); }); // Add a callback for downloading table data diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index fbc07bdd09f6..e99f53bde8d6 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -1301,15 +1301,17 @@ function loadParametricPartTable(table, options={}) { for (var idx = 0; idx < data.length; idx++) { var row = data[idx]; - var pk = row.pk; // Make each parameter accessible, based on the "template" columns row.parameters.forEach(function(parameter) { row[`parameter_${parameter.template}`] = parameter.data; }); - $(table).bootstrapTable('updateByUniqueId', pk, row); + data[idx] = row; } + + // Update the table + $(table).bootstrapTable('load', data); } }); }