diff --git a/InvenTree/part/templates/part/variants.html b/InvenTree/part/templates/part/variants.html
index 00aa786da9..e31d6deee2 100644
--- a/InvenTree/part/templates/part/variants.html
+++ b/InvenTree/part/templates/part/variants.html
@@ -1,5 +1,6 @@
{% extends "part/part_base.html" %}
{% load static %}
+{% load i18n %}
{% load inventree_extras %}
{% block details %}
@@ -7,7 +8,7 @@
-
Part Variants
+ {% trans "Part Variants" %}
@@ -17,45 +18,32 @@
-
-
-
- Variant |
- Description |
- Stock |
-
-
-
- {% for variant in part.variants.all %}
-
-
- {% include "hover_image.html" with image=variant.image hover=True %}
- {{ variant.full_name }}
- {% if not variant.active %}
- INACTIVE
- {% endif %}
- |
- {{ variant.description }} |
- {% decimal variant.total_stock %} |
-
- {% endfor %}
-
+
{% endblock %}
+{% block js_load %}
+{{ block.super }}
+
+
+
+
+
+
+
+
+{% endblock %}
{% block js_ready %}
{{ block.super }}
-
- $('#variant-table').inventreeTable({
- });
+ loadPartVariantTable($('#variants-table'), {{ part.pk }});
$('#new-variant').click(function() {
launchModalForm(
diff --git a/InvenTree/templates/js/part.html b/InvenTree/templates/js/part.html
index a1c3283c1c..2fdcfd57f7 100644
--- a/InvenTree/templates/js/part.html
+++ b/InvenTree/templates/js/part.html
@@ -60,6 +60,98 @@ function toggleStar(options) {
);
}
+
+function loadPartVariantTable(table, partId, options) {
+ /* Load part variant table
+ */
+
+ var params = {
+ ancestor: partId,
+ };
+
+ var cols = [
+ {
+ field: 'pk',
+ title: 'ID',
+ visible: false,
+ switchable: false,
+ },
+ {
+ field: 'name',
+ title: '{% trans "Name" %}',
+ switchable: false,
+ formatter: function(value, row, index, field) {
+ var html = '';
+
+ var name = '';
+
+ if (row.IPN) {
+ name += row.IPN;
+ name += ' | ';
+ }
+
+ name += value;
+
+ if (row.revision) {
+ name += ' | ';
+ name += row.revision;
+ }
+
+ if (row.is_template) {
+ name = '' + name + '';
+ }
+
+ html += imageHoverIcon(row.thumbnail);
+ html += renderLink(name, `/part/${row.pk}/`);
+
+ return html;
+ },
+ },
+ {
+ field: 'IPN',
+ title: '{% trans 'IPN' %}',
+ },
+ {
+ field: 'revision',
+ title: '{% trans 'Revision' %}',
+ },
+ {
+ field: 'description',
+ title: '{% trans "Description" %}',
+ },
+ {
+ field: 'in_stock',
+ title: '{% trans "Stock" %}',
+ }
+ ];
+
+ table.inventreeTable({
+ url: "{% url 'api-part-list' %}",
+ name: 'partvariants',
+ showColumns: true,
+ original: params,
+ queryParams: params,
+ formatNoMatches: function() { return "{% trans "No variants found" %}"; },
+ columns: cols,
+ treeEnable: true,
+ rootParentId: partId,
+ parentIdField: 'variant_of',
+ idField: 'pk',
+ uniqueId: 'pk',
+ treeShowField: 'name',
+ sortable: true,
+ search: true,
+ onPostBody: function() {
+ table.treegrid({
+ treeColumn: 0,
+ });
+
+ table.treegrid('collapseAll');
+ }
+ });
+}
+
+
function loadPartTable(table, url, options={}) {
/* Load part listing data into specified table.
*