<script>
    $(document).ready(function() {
        $('#mytable').DataTable({
          dom: 'Bfrtip',
        buttons: [
          { extend: 'pdf', className: 'btn-primary',exportOptions: {columns: [ 1, 2, 3, 4,5,6,7,8]}, },
          { extend: 'excel', className: 'btn-primary',exportOptions: {columns: [1, 2, 3, 4,5,6,7,8]}, },
          { extend: 'csv', className: 'btn-primary',exportOptions: {columns: [1, 2, 3, 4,5,6,7,8]}, },
        ]});
        if($('#usertype').val() == 'staff')
        {
            $('.edit-btn').remove();
            $('.add-btn').remove();
        }
    } );
</script>
<table class="table table-bordered" id="mytable">
  <thead>
    <tr>
      <!-- <th>
         <div class="checkbox-fade fade-in-primary d-">
             <label>
                 <input type="checkbox" value="" id="checkedAll" class="">
             </label>
         </div>
      </th> -->
      <th scope="col">S.No.</th>
      <th scope="col">Name</th>
      <th scope="col">Email</th>
      <th scope="col">Usertype</th>
      <th scope="col">Lead ID</th>
      <th scope="col">Module</th>
      <th scope="col">Action</th>
      <th scope="col">Datetime</th>
    </tr>
  </thead>
  <tbody>
    <?php $i=1; foreach($list as $val){
      if($val['usertype'] == 'admin')
      {
        $userData = $this->model->getRowData('users',['id'=>$val['user_id']]);
        $name = $userData['firstname'].' '.$userData['lastname'];
        $email = $userData['email'];
      }
      else if($val['usertype'] == 'staff')
      {
        $userData = $this->model->getRowData('staff',['id'=>$val['user_id']]);
        $name = $userData['fullname'];
        $email = $userData['emailid'];
      }
      ?>
    <tr>
      <!-- <td>
         <div class="checkbox-fade fade-in-primary d-">
             <label>
                 <input type="checkbox" name="pro[]" value="<?= $val['id'] ?>" class="delete_checkbox checkSingle" id="multiple_delete<?=  $val['id']; ?>">
             </label>
         </div>
      </td> -->
      <th scope="row"><?= $val['id']; ?></th>
      <td><?= $name; ?></td>
      <td><?= $email; ?></td>
      <td><?= $val['usertype']; ?></td>
      <td>#<?= $val['lead_id']; ?></td>
      <td><?= $val['module']; ?></td>
      <td><?= $val['action']; ?></td>
      <td><?= date('d-m-Y h:i a',strtotime($val['created']));?></td>
    </tr>
    <?php } ?>
  </tbody>
</table>
<script>
//multiple delete
$("#checkedAll").change(function() {
    if (this.checked) {
        $(".checkSingle").each(function() {
          $(this).closest('tr').addClass('removeRow');
          this.checked=true;
        });
    } else {
        $(".checkSingle").each(function() {
            this.checked=false;
        });
    }
});
$('.delete_checkbox').click(function(){
    if($(this).is(':checked'))
    {
    $(this).closest('tr').addClass('removeRow');
    }
    else
    {
    $(this).closest('tr').removeClass('removeRow');
    }
});
function changeStatus(id,type)
{
  if (confirm('Are you sure?') == true) {
    var table = 'users';
    var column = 'is_suspended';
    $.ajax({
        url: "<?= base_url('Dashboard/Status'); ?>",
        method: "POST",
        data: {
            id:id,
            type:type,
            table:table,
            column:column
        },
        success:function(res){
          // $('#tb').html(res);
          $("#tb").load("<?= base_url('admin/viewAdmin/') ?>")
        }
    });
  }
};
</script>