Skip to content

Commit 2f38736

Browse files
committed
Natural integer sorting for extra fields
1 parent f395b8a commit 2f38736

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

InteractiveHtmlBom/core/ibom.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ def natural_sort(lst):
148148

149149
bom_table = []
150150

151+
# If some extra fields are just integers then convert the whole column
152+
# so that sorting will work naturally
153+
for i, field in enumerate(config.show_fields):
154+
if field in ["Value", "Footprint"]:
155+
continue
156+
all_num = True
157+
for f in index_to_fields.values():
158+
if not f[i].isdigit() and len(f[i].strip()) > 0:
159+
all_num = False
160+
break
161+
if all_num:
162+
for f in index_to_fields.values():
163+
if f[i].isdigit():
164+
f[i] = int(f[i])
165+
151166
for _, refs in part_groups.items():
152167
# Fixup values to normalized string
153168
if "Value" in group_by and "Value" in config.show_fields:

0 commit comments

Comments
 (0)