Skip to content

Commit

Permalink
Bom table load fix (#3826)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SchrodingersGat authored Oct 21, 2022
1 parent 4ca2aa6 commit 121d68a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 10 additions & 5 deletions InvenTree/templates/js/translated/bom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
2 changes: 1 addition & 1 deletion InvenTree/templates/js/translated/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions InvenTree/templates/js/translated/part.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down

0 comments on commit 121d68a

Please sign in to comment.