<table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
  <thead>
    <tr>
      <th>IP Address</th>
      <th>MAC Address</th>
      <th>Vendor</th>
      <th class="nd_center-cell">DNS</th>
      <th class="nd_center-cell">NetBIOS</th>
      <th>Time Since Last Seen</th>      
    </tr>
  </thead>
</table>

<script type="text/javascript">
$(document).ready(function() {
  var table = $('#data-table').dataTable({
    "deferRender": true,
    "data": [% results | none %],
    "columns": [
      {
        "data": 'ip',
        "render": function(data, type, row, meta) {
          var cell_str = he.encode(data);
          if (type == 'display') {
            if (row.time_last && row.node) {
              cell_str = '<a href="[% search_node | none %]&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 | none %]&q=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>';
            }
          }
          return cell_str;
        }
      }, {
        "data": 'mac',
        "render": function(data, type, row, meta) {
          var cell_str = he.encode(data || '');
          if (type == 'display' && data && row.time_last) {
            cell_str = '<a href="[% search_node | none %]&q=' + encodeURIComponent(data)
              + (row.active ? '' : '&archived=on') + '">' + he.encode(data)
              + (row.active ? '' : '&nbsp;<i class="icon-book text-warning"></i>&nbsp;') + '</a>';
          }
          return cell_str;
        }
      }, {
        "data": 'vendor',
        "className": "nd_nowrap nd_center-cell",
        "render": function(data, type, row, meta) {
          return he.encode(data || '');
        }
      }, {
        "data": 'dns',
        "className": "nd_nowrap nd_center-cell",
        "render": function(data, type, row, meta) {
          return he.encode(data || '');
        }
      }, {
        "data": 'nbname',
        "className": "nd_nowrap nd_center-cell",
        "render": function(data, type, row, meta) {
          return he.encode(data || '');
        }
      }, {
        "data": 'age',
        "render": function(data, type, row, meta) {
          if (type == 'display') {
            return he.encode(data || 'Never').replace(/:00$/,' mins').replace(':',' hours ');
          }
          else {
            // so that sorting works correctly on this column
            return row.time_last;
          }
        }
      }
    ],
[% INCLUDE 'ajax/datatabledefaults.tt' -%]
  });
});
</script>
