<script>
<?php if($page_name=='tools_transfers'){?>
function GetSearchcategory(){
  return $('#tools_category_filter').val();
}
function GetSearchDate(){
  return $('#date_range').val();
}
function GetSearchTool(){
  return $('#tools_filter').val();
}
function GetSearchTransferFrom(){
  return $('#transfer_from_filter').val();
}
function GetSearchTransferTo(){
  return $('#transfer_to_filter').val();
}
<?php } ?>
<?php if($page_name=='data_entry_approval'){?>
  function GetStartDate(){
    return $('#table_filter_start_date').val();
  }
  function GetEndDate(){
    return $('#table_filter_end_date').val();
  }
  function GetSearchWork(){
    return $('#table_filter_work').val();
  }
  function GetSearchUser(){
    return $('#table_filter_user').val();
  }
  function GetSearchApprovalStatus(){
    return $('#table_filter_approval_status').val();
  }
  <?php } ?>
<?php
$page_type='';
if($page_name=='data_entry_approval'){
  $page_type='approval_entries';
}
?>
var tool_transfer_view_table = $('#tool_transfer_view_table').DataTable({
  "ajax":{
    url :"<?php echo base_url().'tools/select_tools_transfer/'.$page_type ?>", // json datasource
    type: "post", // type of method  , by default would be get
    data: function(d){
      <?php if($page_name=='tools_transfers'){?>
      d.category = GetSearchcategory();
      d.date = GetSearchDate();
      d.tool_id = GetSearchTool();
      d.transfer_from = GetSearchTransferFrom();
      d.transfer_to = GetSearchTransferTo();
      <?php } ?>
      <?php if($page_name=='work_profile'){?>
        d.work_id = "<?php echo $work_data->work_id ?>";
        <?php } ?>
        <?php if($page_name=='work_profile_master' || $page_name=='work_summary_master'){?>
          d.work_ids = "<?php echo implode(',',$sub_project_ids)?>";
          <?php } ?>
        <?php if($page_name=='data_entry_approval'){?>
          d.start_date = GetStartDate();
          d.end_date = GetEndDate();
          d.work_id = GetSearchWork();
          d.approval_status = GetSearchApprovalStatus();
          d.user_id = GetSearchUser();
          <?php } ?>
    }
  },
  "bProcessing": true,
  "deferRender": true,
  "bDeferRender": true,
  "scrollX" : true,
  buttons: [
  { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Tool Transfer History' },
  { extend: 'csv', className: 'btn purple btn-outline ' },
  { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
  ],
  dom:"<'row'<'col-sm-6 text-left'B><'col-sm-6 text-right'f>>\n\t\t\t<'row'<'col-sm-12'tr>>\n\t\t\t<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>", // horizobtal scrollable datatable
  "lengthMenu": [
  [25, 50, 100, -1],
    [25, 50, 100, "All"] // change per page values here
    ],
    "columnDefs": [
    {
      "targets": [ 1,14,15,16<?php if($this->session->userdata('user_role')=='auditor'){ echo ",13"; } ?> ],
      className: "hidden"
    }
    ],
    'order': [[1, 'desc']]
  });
$(".table_filter").on("change", function() {
  tool_transfer_view_table.ajax.reload();
});
</script>
