Implemented bootstrap-table for parts list

This commit is contained in:
Oliver 2018-05-02 22:18:58 +10:00
parent fb9142c3fd
commit 024fe04e0e
5 changed files with 86 additions and 28 deletions

View File

@ -17,8 +17,8 @@
{% endif %}
{% if category.has_parts %}
<h4>Parts</h4>
{% include "part/category_parts.html" with parts=category.parts.all %}
<table class='table table-striped table-condensed' id='part-table'>
</table>
{% endif %}
<div class='container-fluid'>
@ -29,6 +29,7 @@
<button class="btn btn-success" id='create-part'>New Part</button>
<button class="btn btn-danger" id='delete-category'>Delete Category</button>
<button class='btn btn-primary' id='get-rows'>Do thing</button>
</div>
{% include 'modals.html' %}
@ -40,7 +41,6 @@
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
{% endblock %}
{% block js_ready %}
$('#part-list').footable();
$("#edit-category").click(function () {
launchModalForm("#modal-form",
@ -84,4 +84,11 @@
follow: true
});
});
{% include "part/category_parts.html" with category=category %}
$("#get-rows").click( function() {
alert($("#part-table").bootstrapTable('getSelections'));
});
{% endblock %}

View File

@ -1,24 +1,58 @@
<table class="table table-striped" data-sorting='true' data-filtering='true' id="part-list">
<thead>
<tr>
<th>Part</th>
<th>Description</th>
<th>Category</th>
<th data-type='number'>Stock</th>
</tr>
</thead>
<tbody>
{% for part in parts %}
<tr>
<td><a href="{% url 'part-detail' part.id %}">{{ part.name }}</a></td>
<td>{{ part.description }}</td>
<td>
{% if part.category %}
<a href="{% url 'category-detail' part.category.id %}">{{ part.category_path }}</a>
$("#part-table").bootstrapTable({
sortable: true,
search: true,
sortName: 'description',
idField: 'pk',
method: 'get',
pagination: true,
rememberOrder: true,
{% if category %}
queryParams: function(p) {
return {
category: {{ category.id }},
}
},
{% endif %}
</td>
<td><a href="{% url 'part-stock' part.id %}">{{ part.total_stock }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
columns: [
{
checkbox: true,
title: 'Select',
searchable: false,
},
{
field: 'pk',
title: 'ID',
visible: false,
},
{
field: 'name',
title: 'Part',
sortable: true,
formatter: function(value, row, index, field) {
return renderLink(value, row.url);
}
},
{
sortable: true,
field: 'description',
title: 'Description',
},
{% if category == None %}
{
sortable: true,
field: 'category_name',
title: 'Category',
formatter: function(value, row, index, field) {
return renderLink(value, row.category_url)
}
},
{% endif %}
{
field: 'total_stock',
title: 'Stock',
searchable: false,
sortable: true,
}
],
url: 'http://127.0.0.1:8000/api/part/',
});

View File

@ -16,8 +16,7 @@
{% include "part/category_subcategories.html" with children=children %}
{% endif %}
<h4>Parts</h4>
{% include "part/category_parts.html" with parts=parts %}
<table class='table table-striped table-condensed' id='part-table'>
<div class='container-fluid'>
<button type='button' class='btn btn-primary' id='create-cat'>
@ -73,6 +72,8 @@
launchModalForm("#modal-form", "{% url 'part-create' %}");
});
{% include "part/category_parts.html" %}
loadTree();
{% endblock %}

View File

@ -0,0 +1,14 @@
function renderLink(text, url) {
if (text && url) {
return '<a href="' + url + '">' + text + '</a>';
}
else if (text) {
return text;
}
else {
return '';
}
}

View File

@ -49,9 +49,11 @@ InvenTree
<script type="text/javascript" src="{% static 'script/select2/select2.js' %}"></script>
<script type='text/javascript' src="{% static 'script/bootstrap-treeview.js' %}"></script>
<script type='text/javascript' src="{% static 'script/bootstrap-table.min.js' %}"></script>
<script type='text/javascript' src="{% static 'script/bootstrap-table-en-US.min.js' %}"></script>
<script type='text/javascript' src="{% static 'script/tables.js' %}"></script>
<script type='text/javascript' src="{% static 'script/trees.js' %}"></script>
<script type='text/javascript' src="{% static 'script/sidenav.js' %}"></script>
<script type='text/javascript' src="{% static 'script/notification.js' %}"></script>