diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js index 8a49454027..ece5973f0f 100644 --- a/InvenTree/templates/js/translated/bom.js +++ b/InvenTree/templates/js/translated/bom.js @@ -812,7 +812,7 @@ function loadBomTable(table, options={}) { // Part column cols.push( { - field: 'sub_part_detail.full_name', + field: 'sub_part', title: '{% trans "Part" %}', sortable: true, switchable: false, @@ -1194,12 +1194,15 @@ function loadBomTable(table, options={}) { response[idx].parentId = bom_pk; } - var row = $(table).bootstrapTable('getRowByUniqueId', bom_pk); + var row = table.bootstrapTable('getRowByUniqueId', bom_pk); row.sub_assembly_received = true; - $(table).bootstrapTable('updateByUniqueId', bom_pk, row, true); + table.bootstrapTable('updateByUniqueId', bom_pk, row, true); table.bootstrapTable('append', response); + + // Auto-expand the newly added row + $(`.treegrid-${bom_pk}`).treegrid('expand'); }, error: function(xhr) { console.error('Error requesting BOM for part=' + part_pk); @@ -1252,28 +1255,39 @@ function loadBomTable(table, options={}) { table.treegrid({ treeColumn: 1, - onExpand: function() { - } }); table.treegrid('collapseAll'); // Callback for 'load sub assembly' button - $(table).find('.load-sub-assembly').click(function(event) { + table.find('.load-sub-assembly').click(function(event) { event.preventDefault(); var pk = $(this).attr('pk'); - var row = $(table).bootstrapTable('getRowByUniqueId', pk); + var row = table.bootstrapTable('getRowByUniqueId', pk); // Request BOM data for this subassembly requestSubItems(row.pk, row.sub_part); row.sub_assembly_requested = true; - $(table).bootstrapTable('updateByUniqueId', pk, row, true); + table.bootstrapTable('updateByUniqueId', pk, row, true); }); + + var data = table.bootstrapTable('getData'); + + for (var idx = 0; idx < data.length; idx++) { + var row = data[idx]; + + if (!row.parentId) { + row.parentId = parent_id; + + table.bootstrapTable('updateByUniqueId', row.pk, row, true); + } + } }, - onLoadSuccess: function() { + onLoadSuccess: function(data) { + if (options.editable) { table.bootstrapTable('uncheckAll'); }