Bug fix for multi-level display in BOM table (#3720)

- Multi-level BOM loading was broken
- Using the wrong column name for 'treeShowField'
- Also adds functionality to auto-expand sub-part when loading
This commit is contained in:
Oliver 2022-09-27 13:30:25 +10:00 committed by GitHub
parent bfbafb9912
commit fbde70d531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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');
}