DataTables for IP inventory report

This commit is contained in:
Eric A. Miller
2014-05-29 20:32:44 -04:00
parent 7d5c3f3191
commit 8590b6781f
2 changed files with 45 additions and 25 deletions

View File

@@ -1,30 +1,49 @@
<table class="table table-bordered table-condensed table-striped nd_floatinghead">
<table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
<thead>
<tr>
<th>Node</th>
<th class="nd_center-cell">DNS</th>
<th class="nd_center-cell">Last Used</th>
<th class="nd_center-cell">First Discovered</th>
<th>DNS</th>
<th>Last Used</th>
<th>First Discovered</th>
</tr>
</thead>
</tbody>
[% FOREACH row IN results %]
<tr>
[% IF row.time_last && row.node %]
<td><a href="[% search_node %]&q=[% row.ip | uri %][% '&archived=on' IF NOT row.active %]">
[% row.ip | html_entity %]</a>
[% '&nbsp;<i class="icon-book text-warning"></i>&nbsp;' IF NOT row.active %]
</td>
[% ELSIF row.time_last %]
<td><a href="[% search_device %]&q=[% row.ip | uri %]">[% row.ip | html_entity %]</a>
</td>
[% ELSE %]
<td>[% row.ip | html_entity %]</td>
[% END %]
<td class="nd_center-cell">[% row.dns | html_entity %]</td>
<td class="nd_center-cell">[% row.age || 'Never' | html_entity %]</td>
<td class="nd_center-cell">[% row.time_first || 'Never' | html_entity %]</td>
</tr>
[% END %]
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
var table = $('#data-table').dataTable({
"deferRender": true,
"data": [% results %],
"columns": [
{
"data": 'ip',
"render": function(data, type, row, meta) {
var cell_str = he.encode(data);
if (row.time_last && row.node) {
cell_str = '<a href="[% search_node %]&q=' + encodeURIComponent(data) + (row.active ? '' : '&archived=on') + '">' + he.encode(data) + (row.active ? '' : '&nbsp;<i class="icon-book text-warning"></i>&nbsp;') + '</a>';
}
else if (row.time_last) {
cell_str = '<a href="[% search_device %]&q=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>';
}
return cell_str;
}
}, {
"data": 'dns',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, {
"data": 'age',
"render": function(data, type, row, meta) {
return he.encode(data || 'Never');
}
}, {
"data": 'time_first',
"render": function(data, type, row, meta) {
return he.encode(data || 'Never');
}
}
]
});
});
</script>