Convert device module inventory web report to DataTables server-side processing

This commit is contained in:
Eric A. Miller
2014-06-08 22:42:07 -04:00
parent 56e1bd9911
commit f00ebf9ecc
2 changed files with 72 additions and 29 deletions

View File

@@ -1,3 +1,4 @@
[% USE url %]
[% IF opt %]
<table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
<thead>
@@ -14,21 +15,6 @@
<th>FW Version</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Device</th>
<th>Description</th>
<th>Name</th>
<th>Class</th>
<th>Type</th>
<th>Model</th>
<th>Serial</th>
<th>HW Version</th>
<th>SW Version</th>
<th>FW Version</th>
</tr>
</tfoot>
</table>
[% ELSE %]
<table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
@@ -44,10 +30,16 @@
<script type="text/javascript">
$(document).ready(function() {
var table = $('#data-table').dataTable({
"deferRender": true,
"data": [% results %],
[% IF opt %]
"processing": true,
"serverSide": true,
"searching": false,
"stateSave": true,
"pageLength": 25,
"order": [[ 0, "desc" ]],
"ajax": '/ajax/content/report/moduleinventory/data?[% url(params('query').hash) %]',
"columns": [
[% IF opt %] {
{
"data": 'ip',
"render": function(data, type, row, meta) {
return '<a href="[% uri_for('/device') %]?tab=modules&q=' + encodeURIComponent(data) + '">' + he.encode(row.device.dns || row.device.name || row.ip) + '</a>';
@@ -98,7 +90,12 @@ $(document).ready(function() {
return he.encode(data || '');
}
}
[% ELSE %] {
]
[% ELSE %]
"deferRender": true,
"data": [% results %],
"columns": [
{
"data": 'class',
"render": function(data, type, row, meta) {
return '<a href="[% uri_for('/report/moduleinventory') %]?class=' + encodeURIComponent(data) + '">' + he.encode(capitalizeFirstLetter(data + '')) + '</a>';
@@ -109,8 +106,8 @@ $(document).ready(function() {
return data.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
[% END %]
]
[% END %]
});
});
</script>