Fixed datatables rendering
This commit is contained in:
parent
b6a00c2b30
commit
9ba413c634
|
@ -21,9 +21,6 @@
|
|||
<th>Type</th>
|
||||
<th>Package</th>
|
||||
<th>Attributes</th>
|
||||
<th>Attributes (Names)</th>
|
||||
<th>Attributes (Units)</th>
|
||||
<th>Attributes (Values)</th>
|
||||
<th>Value</th>
|
||||
<th>Stock</th>
|
||||
<th></th>
|
||||
|
@ -40,9 +37,6 @@
|
|||
<th>Type</th>
|
||||
<th>Package</th>
|
||||
<th>Attributes</th>
|
||||
<th>Attributes (Names)</th>
|
||||
<th>Attributes (Units)</th>
|
||||
<th>Attributes (Values)</th>
|
||||
<th>Value</th>
|
||||
<th>Stock</th>
|
||||
<th></th>
|
||||
|
@ -56,14 +50,18 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
function format(d) {
|
||||
var tbody = '<tr><th colspan="2">Attributes</th></tr><tr><th>Name</th><th>Value</td></tr>'
|
||||
var tbody = '<tr><th colspan="2">Attributes</th></tr><tr><th>Name</th><th>Value</td></tr>';
|
||||
|
||||
d.attributes.forEach(function(item, index) {
|
||||
tbody +=
|
||||
'<th style="text-align:left">'+ item.name +':</th>'+
|
||||
'<td style="text-align:right">'+ item.value + item.unit +'</td>'+
|
||||
'</tr>'
|
||||
tbody += '<th style="text-align:left">'+ item.name +':</th>';
|
||||
if (item.name.startsWith("url")) {
|
||||
tbody += '<td style="text-align:left"><a href="'+ item.value +'">external</a></td>';
|
||||
} else {
|
||||
tbody += '<td style="text-align:right">'+ item.value + item.unit +'</td>';
|
||||
}
|
||||
tbody += '</tr>';
|
||||
});
|
||||
return '<table class="pure-table pure-table-bordered" cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+ tbody+ '</table>'
|
||||
return '<table class="pure-table pure-table-bordered" cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+ tbody+ '</table>';
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
@ -75,15 +73,15 @@
|
|||
select: true,
|
||||
stateSave: true,
|
||||
columns: [
|
||||
{ /* 0 */
|
||||
orderable: false,
|
||||
{
|
||||
className: 'details-control details-control-icon',
|
||||
orderable: false,
|
||||
data: null,
|
||||
defaultContent: ''
|
||||
},
|
||||
{ /* 1 */
|
||||
orderable: false,
|
||||
{
|
||||
className: 'part-control',
|
||||
orderable: false,
|
||||
defaultContent: '',
|
||||
render: function(data, type, row, meta) {
|
||||
if (type === "display") {
|
||||
|
@ -92,9 +90,9 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{ /* 2 */
|
||||
orderable: false,
|
||||
{
|
||||
className: 'part-control',
|
||||
orderable: false,
|
||||
defaultContent: '',
|
||||
render: function(data, type, row, meta) {
|
||||
if (type === "display") {
|
||||
|
@ -102,15 +100,15 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{ /* 3 */
|
||||
{
|
||||
data: 'name'
|
||||
},
|
||||
{ /* 4 */
|
||||
{
|
||||
data: 'description'
|
||||
},
|
||||
{ /* 5 */
|
||||
orderable: false,
|
||||
{
|
||||
data: 'datasheet',
|
||||
orderable: false,
|
||||
render: function(data, type, row, meta) {
|
||||
if (data !== null && type === 'display') {
|
||||
return "<a href='/parts/datasheet/" + data.id + "/view'>🖹</a>";
|
||||
|
@ -119,16 +117,16 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{ /* 6 */
|
||||
{
|
||||
data: "parttype.label"
|
||||
},
|
||||
{ /* 7 */
|
||||
{
|
||||
data: "package.label"
|
||||
},
|
||||
{ /* 8 */
|
||||
orderable: false,
|
||||
{
|
||||
data: 'attributes',
|
||||
className: 'dt-body-center details-control',
|
||||
orderable: false,
|
||||
render: function(data, type, row, meta) {
|
||||
if (type === 'display') {
|
||||
return data.length;
|
||||
|
@ -137,34 +135,16 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{ /* 9 */
|
||||
orderable: false,
|
||||
visible: false,
|
||||
className: 'notToggleVis',
|
||||
data: "attributes[, ].name",
|
||||
},
|
||||
{ /* 9 */
|
||||
orderable: false,
|
||||
visible: false,
|
||||
className: 'notToggleVis',
|
||||
data: "attributes[, ].unit",
|
||||
},
|
||||
{ /* 9 */
|
||||
orderable: false,
|
||||
visible: false,
|
||||
className: 'notToggleVis',
|
||||
data: "attributes[, ].value",
|
||||
},
|
||||
{ /* 10 */
|
||||
{
|
||||
data: 'value'
|
||||
},
|
||||
{ /* 11 */
|
||||
{
|
||||
data: 'stock',
|
||||
className: 'dt-body-right'
|
||||
},
|
||||
{ /* 12 */
|
||||
orderable: false,
|
||||
{
|
||||
className: 'part-control',
|
||||
orderable: false,
|
||||
defaultContent: '',
|
||||
render: function(data, type, row, meta) {
|
||||
if (type === "display") {
|
||||
|
@ -175,30 +155,26 @@
|
|||
]
|
||||
});
|
||||
|
||||
tableCatalog.column(9).visible(false);
|
||||
tableCatalog.column(10).visible(false);
|
||||
tableCatalog.column(11).visible(false);
|
||||
$('#parts-catalog tbody').on('click', 'td.details-control', function() {
|
||||
var tr = $(this).closest('tr');
|
||||
var row = tableCatalog.row(tr);
|
||||
|
||||
$('#parts-catalog tbody').on('click', 'td.details-control', function() {
|
||||
var tr = $(this).closest('tr');
|
||||
var row = tableCatalog.row(tr);
|
||||
|
||||
if (row.child.isShown()) {
|
||||
row.child.hide();
|
||||
tr.removeClass('shown');
|
||||
} else {
|
||||
row.child(format(row.data())).show();
|
||||
tr.addClass('shown');
|
||||
}
|
||||
});
|
||||
|
||||
$('#parts-catalog tbody').on('click', 'a.part-delete', function() {
|
||||
//event.preventDefault();
|
||||
if (confirm('Are you sure?')) {
|
||||
var url = $(this).data('href');
|
||||
document.location = url;
|
||||
}
|
||||
});
|
||||
if (row.child.isShown()) {
|
||||
row.child.hide();
|
||||
tr.removeClass('shown');
|
||||
} else {
|
||||
row.child(format(row.data())).show();
|
||||
tr.addClass('shown');
|
||||
}
|
||||
});
|
||||
|
||||
$('#parts-catalog tbody').on('click', 'a.part-delete', function() {
|
||||
//event.preventDefault();
|
||||
if (confirm('Are you sure?')) {
|
||||
var url = $(this).data('href');
|
||||
document.location = url;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue