$(document).on('click', 'td.details-control', function() {

    var tr = $(this).closest('tr');
    var row = table.row(tr);
    var tableId = 'inventory-' + row.data().id;
    var client_id = row.data().id;
    if (row.child.isShown()) {
      // This row is already open - close it
      row.child.hide();
      tr.removeClass('shown');
    } else {
      // Open this row
      row.child(template(row.data())).show();
      initTable(tableId, row.data(),client_id);
      console.log(row.data());
      tr.addClass('shown');
      tr.next().find('td').addClass('no-padding bg-gray');
    }
  });

  function initTable(tableId, data,client_id) {
    $('#' + tableId).DataTable({
      paging: false,
      searching: false,
      ordering: false,
      info:false,
      ajax: data.details_url,
      columns: [
        { data: 'DT_RowIndex'},
        { data: 'agency'},
        { data: 'item'},
      ],
      "initComplete": function(settings, json) {
        $('.main-spinner').hide();
      }
    });
  }