
var table 
    
    

    function edit_items(itemid){
       
      
       
      $.ajax({
                      url : 'models/crul_customer.php',
                      type : 'POST',
                      data : {id:itemid,
                        type:'get_edit'},
                      dataType : 'json',
                      success : function(response) {
                        if(response.is_success==true){

                            $("#edit_objid").val(itemid);
                            $("#edit_customer_full_name").val(response.data[0].customer_full_name);
                            $("#edit_customer_email").val(response.data[0].customer_email);
                            $("#edit_customer_phone").val(response.data[0].customer_phone);
                            $("#edit_customer_phone2").val(response.data[0].customer_phone2);
                            $("#edit_customer_address").val(response.data[0].customer_address);
                            $("#edit_customer_job_title").val(response.data[0].customer_job_title);
                            $("#edit_username").val(response.data[0].customer_username);
                            $("#edit_branch_id_fk").val(response.data[0].branch_id_fk);
                            $("#edit_city_id_fk").val(response.data[0].city_id_fk);


                            $('#edit_form_cont').modal('toggle');

                        }else{
                          alert(response.data)
                        }
                          
                          
                            
                      },
                      complete: function() {
                             //  me.data('requestRunning', false);
                      }

      }); // submit ajax

       
    }

    function delete_items(itemid) {
      
        swal({
            title: Translation("هل انت متأكد؟!"),
            text: Translation("سوف لن تستطيع استرجاع المعلومات المرتبطة بهذا السجل في حالة المسح"),
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#EF5350",
            confirmButtonText: Translation("موافق: امسح!"),
            cancelButtonText: Translation("الغاء الامر"),
            closeOnConfirm: false,
            closeOnCancel: true
        },
        function(isConfirm){
            if (isConfirm) {
              $.ajax({
                url: "models/crul_customer.php",
                type:"POST",
                data: {"type":"delete","obj_id":itemid} ,
                complete:function(){
                 // hideLoader();
                },
                beforeSend:function(){
                 // showLoader("Deleting Category");
                },
                success: function(res) {
                  if(res == 1){
                    swal({
                                title: Translation("حذف!"),
                                text: Translation("تم حذف الزبون بنجاح"),
                                confirmButtonColor: "#66BB6A",
                                type: "success"
                            });
                    $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                  }else{
                    swal({
                                title: Translation("خطأ"),
                                text: Translation(res),
                                confirmButtonColor: "#2196F3",
                                type: "error"
                            });
                  }
                }
            });
            }
        }); // /confirm
    }

 
    function get_Profile_price(){

            $.ajax({
                  url : 'models/crul_profile_price.php',
                  type : 'POST',
                  data : {type:'get'},
                  dataType : 'json',
                  success : function(response) {
                    //console.log(response)
                      var attach ='<option value="" selected="selected">'+Translation('تحديد ملف السعر')+'</option>';
                      var aaa='';
                        for(var i=response.length-1 ; i >= 0;i--){
                          var tp ="";
                          attach = attach + '<option data-subtext="'+tp+'" value="'+response[i][0]+'">'+response[i][1]+'</option>';
                          aaa = aaa + '<option  value="'+response[i][0]+'">'+response[i][1]+'</option>';

                        }
                        $("#price_profile_id_fk").html(attach);
                        $("#edit_price_profile_id_fk").html(attach);
                        
                  },
                  complete: function() {
                         //  me.data('requestRunning', false);
                  }

            }); // submit ajax

    }


    function get_City(){

            $.ajax({
                  url : 'models/crul_customer.php',
                  type : 'POST',
                  data : {type:'get_city'},
                  dataType : 'json',
                  success : function(response) {
                    //console.log(response)
                      var attach ='<option value="" selected="selected">'+Translation('تحديد المحافظة')+'</option>';
                      var aaa='';
                        for(var i=response.length-1 ; i >= 0;i--){
                          var tp ="";
                          attach = attach + '<option data-subtext="'+tp+'" value="'+response[i][0]+'">'+response[i][1]+'</option>';
                         
                        }
                        $("#city_id_fk").html(attach);
                        $("#edit_city_id_fk").html(attach);
                        
                  },
                  complete: function() {
                         //  me.data('requestRunning', false);
                  }

            }); // submit ajax

    }

    function get_Branch(){

                $.ajax({
                      url : 'models/crul_branch.php',
                      type : 'POST',
                      data : {type:'get'},
                      dataType : 'json',
                      success : function(response) {
                          var attach ='<option class="text-black text-danger-800" selected="selected" value="">'+Translation('اختيار الفرع')+'</option>';
                          
                          for(var i=response.length-1 ; i >= 0;i--){

                            var tp =response[i][2];
                              
                            attach = attach + '<option class="text-black text-danger-800" data-subtext="'+Translation('الموقع')+' : '+response[i]['location']+'" value="'+response[i]['branch_id']+'">'+response[i]['branch_name']+'</option>';
                              
                               
                              
                          }
                          $("#branch_id_fk").html(attach);
                          // $('#branch_id_fk').selectpicker('refresh');

                          $("#edit_branch_id_fk").html(attach);
                          // $('#edit_branch_id_fk').selectpicker('refresh');
                            
                      },
                      complete: function() {
                             //  me.data('requestRunning', false);
                      }

                }); // submit ajax

    }

    function change_password(itemid,itemName){
      
      $("#edit_objidPass").val(itemid);

      $('#edit_form_cont1').modal('toggle');
   }


    function deactive_items(itemid) {
      block = $("#list_of_items_tbl");
         // bootstrap modal confirmation box
           swal({
               title: Translation("هل انت متأكد؟!"),
               text: Translation("You will deactivate this user!"),
               type: "warning",
               showCancelButton: true,
               confirmButtonColor: "#EF5350",
               confirmButtonText: Translation("Yes, De-Activate it!"),
               cancelButtonText: Translation("الغاء الامر"),
               closeOnConfirm: false,
               closeOnCancel: true
           },
           function(isConfirm){
               if (isConfirm) {
                 $.ajax({
                   url: "models/crul_customer.php",
                   type:"POST",
                   dataType: "JSON",
                   data: {"type":"deactive","obj_id":itemid} ,
                   complete:function(){
                    // hideLoader();
                   },
                   beforeSend:function(){
                    // showLoader("Deleting Category");
                   },
                   success: function(res) {

                      if(res.is_success == true){
                       
                       $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                          swal({
                                   title: Translation("تمت العملية"),
                                   text: Translation(res.data),
                                   confirmButtonColor: "#2196F3",
                                   type: "success"
                               });
                      }else{
                          swal({
                                   title: Translation("خطأ"),
                                   text: Translation(res.data),
                                   confirmButtonColor: "#2196F3",
                                   type: "error"
                               });
                      }
                     
                   }
               });
               }
           }); // /confirm
    }


    function active_items(itemid) {
          block = $("#list_of_items_tbl");
             // bootstrap modal confirmation box
               swal({
                   title: Translation("هل انت متأكد؟!"),
                   text: Translation("You will Activate this user!"),
                   type: "warning",
                   showCancelButton: true,
                   confirmButtonColor: "#EF5350",
                   confirmButtonText: Translation("Yes, Activate it!"),
                   cancelButtonText: Translation("الغاء الامر"),
                   closeOnConfirm: false,
                   closeOnCancel: true
               },
               function(isConfirm){
                   if (isConfirm) {
                     $.ajax({
                       url: "models/crul_customer.php",
                       type:"POST",
                       dataType: "JSON",
                       data: {"type":"active","obj_id":itemid} ,
                       complete:function(){
                        // hideLoader();
                       },
                       beforeSend:function(){
                        // showLoader("Deleting Category");
                       },
                       success: function(res) {
                         if(res.is_success == true){
                           
                           $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                              swal({
                                       title: Translation("تمت العملية"),
                                       text: Translation(res.data),
                                       confirmButtonColor: "#2196F3",
                                       type: "success"
                                   });
                          }else{
                              swal({
                                       title: Translation("خطأ"),
                                       text: Translation(res.data),
                                       confirmButtonColor: "#2196F3",
                                       type: "error"
                                   });
                          }
                       }
                   });
                   }
               }); // /confirm
    }

$(document).ready(function() {


    get_City();
    get_Branch();
  
    $('#add_form').submit(function(event) {
            event.preventDefault();
            

            var customer_full_name    = $("#customer_full_name").val();
            var customer_email        = $("#customer_email").val();
            var customer_phone        = $("#customer_phone").val();
            var customer_phone2       = $("#customer_phone2").val();
            var customer_address      = $("#customer_address").val();
            var customer_job_title    = $("#customer_job_title").val();
            // var price_profile_id_fk   = $("#price_profile_id_fk").val();
            var customer_company      = $("#customer_company").val();
            var city_id_fk            = $("#city_id_fk").val();
            var branch_id_fk          = $("#branch_id_fk").val();
            var note                  = $("#note").val();

            var username              = $("#username").val();
            var password              = $("#password").val();
            var repassword            = $("#repassword").val();


            var Check1 = true;
            var Check2 = true;
            var Check3 = true;
            var Check4 = true;
            var Check5 = true;

            var Check1    = Checks('customer_full_name');
            // var Check2    = Checks('customer_company');
            // var Check3    = Checks('customer_phone');
            var Check4    = Checks('city_id_fk');
            var Check5    = Checks('branch_id_fk');
            


            if(Check1 && Check2 && Check3 && Check4 && Check5){
              $("#submit_add_btn").attr('disabled',true);
                $.ajax({
                    url: "models/crul_customer.php",
                    type:"POST",
                    dataType : "JSON",
                    data : {customer_full_name:customer_full_name,
                            customer_email:customer_email,
                            customer_phone:customer_phone,
                            customer_phone2:customer_phone2,
                            customer_address:customer_address,
                            customer_job_title:customer_job_title,
                            city_id_fk:city_id_fk,
                            customer_company:customer_company,
                            note:note,
                            username  :username,
                            password  :password,
                            repassword  :repassword,
                            branch_id_fk  :branch_id_fk,

                            // allowed_max_money:allowed_max_money,
                            type:'create'}
                })
                .done(function(res) {
                  //alert(res);
                  if(res.is_success == false){
                      noty({
                        width: 200,
                        text: Translation(res.data),
                        type: 'error',
                        dismissQueue: true,
                        timeout: 3000,
                        layout: 'topRight',
                      });
                      $("#add-form-cont").collapse('hide');
                  }else{
                      $("#add_form")[0].reset();
                      $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                      $("#add-form-cont").collapse('hide');
                      noty({
                                      width: 200,
                                      text: Translation(res.data),
                                      type: 'success',
                                      dismissQueue: true,
                                      timeout: 3000,
                                      layout: 'topRight',
                                });
                  }
                  $("#submit_add_btn").attr('disabled',false);
                })
                .fail(function(err) {
                   swal({
                      title: Translation("خطأ"),
                      text: (err),
                      confirmButtonColor: "#66BB6A",
                      type: "error"
                    });
                   $("#submit_add_btn").attr('disabled',false);
                })
                .always(function() {
                    console.log("complete");
                });
            }

    });


     // submit editable Visa Application form
  $('#edit_form').submit(function(event) {
            event.preventDefault();
           
            
            var catId    = $("#edit_objid").val();

            var customer_full_name    = $("#edit_customer_full_name").val();
            var customer_email        = $("#edit_customer_email").val();
            var customer_phone        = $("#edit_customer_phone").val();
            var customer_phone2       = $("#edit_customer_phone2").val();
            var customer_address      = $("#edit_customer_address").val();
            var customer_job_title    = $("#edit_customer_job_title").val();
            var city_id_fk            = $("#edit_city_id_fk").val();
            var customer_company      = $("#edit_customer_company").val();
            var branch_id_fk          = $("#edit_branch_id_fk").val();
            var note                  = $("#edit_note").val();
            var username              = $("#edit_username").val();

            // var allowed_max_money     = $("#edit_allowed_max_money").val();


            var Check1 = true;
            var Check2 = true;
            var Check3 = true;
            var Check4 = true;
            var Check5 = true;

            var Check1    = Checks('edit_customer_full_name');
            // var Check2    = Checks('edit_customer_company');
            // var Check3    = Checks('edit_customer_phone');
            var Check4    = Checks('edit_city_id_fk');
            var Check5    = Checks('edit_branch_id_fk');

            

            if(Check1 && Check2 && Check3 && Check4 && Check5){
                $.ajax({
                    url: "models/crul_customer.php",
                    type:"POST",
                    dataType : "JSON",
                    data : {customer_full_name:customer_full_name,
                            customer_email:customer_email,
                            customer_phone:customer_phone,
                            customer_phone2:customer_phone2,
                            customer_address:customer_address,
                            customer_job_title:customer_job_title,
                            city_id_fk:city_id_fk,
                            customer_company:customer_company,
                            note:note,
                            username    :username,
                            branch_id_fk    :branch_id_fk,

                            // allowed_max_money:allowed_max_money,
                            obj_id:catId,
                            type:'update'},
                    complete:function(){
                      
                    },
                    beforeSend:function(){
                      
                    },
                    success: function(res) {
                      if(res.is_success == false){
                          noty({
                            width: 200,
                            text: Translation(res.data),
                            type: 'error',
                            dismissQueue: true,
                            timeout: 3000,
                            layout: 'topRight',
                          });
                        $("#edit-form-cont").collapse('hide');
                        $("#edit_form")[0].reset();
                        
                      }else {
                        $("#edit_form")[0].reset();
                        $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                        
                        $('#edit_form_cont').modal('toggle');

                        noty({
                                        width: 200,
                                        text: Translation(res.data),
                                        type: 'success',
                                        dismissQueue: true,
                                        timeout: 3000,
                                        layout: 'topRight',
                                  });
                      }
                    }
                });
              }
    });

    
    $('#edit_formPass').on('submit', function(e){
         
         e.preventDefault();

         
         var password      = $("#edit_password").val();
         var repassword    = $("#edit_repassword").val();
         
         var catId         = $("#edit_objidPass").val();
         
         var Check1 = true;
         var Check2 = true;
         var Check3 = true;
         

         
         
         if(password !=repassword) {
            $("#edit_password").closest('.form-group').addClass('has-error');
            $("#edit_password").closest('.form-group').removeClass('has-success');
            $("#edit_repassword").closest('.form-group').addClass('has-error');
            $("#edit_repassword").closest('.form-group').removeClass('has-success');
            
            noty({
                     width: 200,
                     text: Translation("Passwords Does Not Match"),
                     type: 'error',
                     dismissQueue: true,
                     timeout: 3000,
                     layout: 'top',
               });
            Check3 = false;
         }else{
            $("#edit_password").closest('.form-group').removeClass('has-error');
            $("#edit_password").closest('.form-group').addClass('has-success');
            $("#edit_repassword").closest('.form-group').removeClass('has-error');
            $("#edit_repassword").closest('.form-group').addClass('has-success');

            Check3 = true;
         }

         Check1 = Checks('edit_password');
         Check2 = Checks('edit_repassword');

         if(password.length <6) {
            $("#edit_password").closest('.form-group').addClass('has-error');
            $("#edit_password").closest('.form-group').removeClass('has-success');
            $("#edit_repassword").closest('.form-group').addClass('has-error');
            $("#edit_repassword").closest('.form-group').removeClass('has-success');
            
            noty({
                     width: 200,
                     text: Translation("Passwords Length should be at least 6 Characters!!"),
                     type: 'error',
                     dismissQueue: true,
                     timeout: 3000,
                     layout: 'top',
               });
            Check3 = false;
         }

         
         

         if(Check1 && Check2  && Check3){
               
               $.ajax({
                    url  : "models/crul_saleman.php",
                    type : "POST",
                    dataType: "JSON",
                    data : {password:password,repassword:repassword,obj_id:catId,type:'change_password'}
                })
                .done(function(res) {
                  console.log(res);
                  if(res.is_success == false){
                      noty({
                                      width: 200,
                                      text: Translation(res.data),
                                      type: 'error',
                                      dismissQueue: true,
                                      timeout: 3000,
                                      layout: 'topRight',
                                });
                      $("#edit_form_cont1").modal('toggle');
                  }else{
                      $("#edit_formPass")[0].reset();
                      $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                      $("#edit_form_cont1").modal('toggle');
                      noty({
                                      width: 200,
                                      text: Translation(res.data),
                                      type: 'success',
                                      dismissQueue: true,
                                      timeout: 3000,
                                      layout: 'topRight',
                                });
                  }
                })
                .fail(function(err) {
                   swal({
                      title: Translation("خطأ"),
                      text: Translation(err),
                      confirmButtonColor: "#66BB6A",
                      type: "error"
                    });
                })
                .always(function() {
                    console.log("complete");
                });


              
         }else{
               noty({
                                       width: 200,
                                       text: Translation('Check Your Credentials!!'),
                                       type: 'error',
                                       dismissQueue: true,
                                       timeout: 3000,
                                       layout: 'top',
                                 });
         }
         
    });

    
    

});






$(function() {
//var singleSelect = $('.datatable-column-search-inputs').DataTable();
    
  // Initialize plugin Tag Input
    $('.tokenfield-primary').tokenfield();

    // Add class when token is created
    $('.tokenfield-primary').on('tokenfield:createdtoken', function (e) {
        $(e.relatedTarget).addClass('bg-primary')
    });




   // Setting datatable defaults
    $.extend( $.fn.dataTable.defaults, {
        autoWidth: false,
        columnDefs: [{ 
            orderable: false,
            width: '100px',
            targets: [ 4 ]
        }],
        dom: '<"datatable-header"fBl><"datatable-scroll"t><"datatable-footer"ip>',
        language: {
            search: '<span>'+Translation('بحث')+'</span> _INPUT_',
            searchPlaceholder: Translation('بحث عن')+' ...',
            lengthMenu: '<span>'+Translation('عرض')+' :</span> _MENU_',
            paginate: { 'first': 'First', 'last': 'Last', 'next': '&larr;', 'previous': '&rarr;' }
        },
        drawCallback: function () {
            $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').addClass('dropup');
        },
        preDrawCallback: function() {
            $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').removeClass('dropup');
        }
    });

    

    // Individual column searching with text inputs
    $('.datatable-column-search-inputs tfoot td').not(':last-child').each(function () {
        var title = $('.datatable-column-search-inputs thead th').eq($(this).index()).text();
        $(this).html('<input type="text" class="form-control input-sm" placeholder="'+Translation('بحث عن')+' '+title+'" />');
    });
    
    
   var query_typ  = getQueryVariable("typ");

   
   var table = $('.datatable-column-search-inputs').DataTable({
        buttons: {            
            buttons: [
                {
                    extend: 'copyHtml5',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: [ 0, ':visible' ]
                    }
                },
                {
                    extend: 'excelHtml5',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                    extend: 'pdfHtml5',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                    extend: 'print',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                    extend: 'colvis',
                    text: '<i class="icon-three-bars"></i> <span class="caret"></span>',
                    className: 'btn bg-blue btn-icon'
                }
                
            ]
        },
        lengthMenu: [
            [  10, 25, 50, 100 ],
            [  '10', '25', '50', '100' ]
        ],
        "processing": true,
        "serverSide": true,
        "ajax": {
        "url" : "models/crul_customer.php",
        "data": function(d){
          d.type = "load";
          if(query_typ !='not'){
            d.typ =query_typ ;
          }
        }
        },
        drawCallback: function() {
                  $('[data-popup=tooltip]').tooltip();
                  $('[data-popup=popover-custom]').popover({
                    template: '<div class="popover  border-teal-400"><div class="arrow"></div><h3 class="popover-title bg-teal-400"></h3><div class="popover-content"></div></div>'
                  });

            },
        "columnDefs": [
          {
              "targets": 9,
              "data": null,
              "render": function (data,type,row) {

                        if(IS_VIEW==0){
                          var status = ``;

                          if(row[9]==0){
                             status= status + `<li class='text-danger-600'>
                                                <a  class='text-warning' onclick="deactive_items(`+row[0]+`,'`+row[1]+`')" data-popup='tooltip' data-original-title='`+Translation('De-Activate User')+`'>
                                                    <i class='icon-user-block icon-2x'></i>
                                                </a>
                                            </li>`;
                          }else{
                             status=status +`<li class='text-danger-600'>
                                                <a  class='text-success-400' onclick="active_items(`+row[0]+`,'`+row[1]+`')" data-popup='tooltip' data-original-title='`+Translation('Activate User')+`'>
                                                    <i class='icon-user-check icon-2x'></i>
                                                </a>
                                            </li>`;
                          }

                            return  `<ul class='icons-list pull-right'>
                                      
                                        <li class='text-primary-600'>
                                            <a  class='text-primary-400' onclick="edit_items(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('تحرير')+`'>
                                                <i class='icon-pencil7 icon-2x'></i>
                                            </a>
                                        </li>

                                        <li class='text-danger-600'>
                                            <a  class='text-info-400' onclick="change_password(`+row[0]+`,'`+row[1]+`')" data-popup='tooltip' data-original-title='Change Password' title='`+Translation('Change Password')+`'>
                                                <i class='icon-key icon-2x'></i>
                                            </a>
                                        </li>
                                        ${status}
                                        <li class='text-danger-600'>
                                            <a  class='text-danger-400' onclick="delete_items(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('حذف')+`'>
                                                <i class='icon-trash icon-2x'></i>
                                            </a>
                                        </li>

                                    </ul>`;
                        }else{
                            return '';
                        }
                    }
          },

          {
             "render": function(data, type, row){


                      // return  `<a href='index.php?p=invoice&id=`+row[0]+`'  data-popup='tooltip' data-original-title='Show All Invoices for this Customer'>`+data+`</a>`;
                      return  `<a onclick="load_account_statment(`+row[0]+`)"  data-popup='tooltip' data-original-title='`+Translation('عرض جميع كشوفات الحساب لهذا الزبون')+`'>`+data+`</a>`;


             },
             "targets": 2
          },

          {
             "render": function(data, type, row){

                   
                     status = '<span class="badge bg-success  btn-block ">'+data+'</span>';
                  
                     status1 = '<span class="badge bg-violet  btn-block ">'+row[10]+'</span>';
                  
                      // return  `<a href='index.php?p=invoice&id=`+row[0]+`'  data-popup='tooltip' data-original-title='Show All Invoices for this Customer'>`+data+`</a>`;
                      return  status + status1;


             },
             "targets": 3
          },


          // {
          //    "render": function(data, type, row){

          //          if(data ==0){
          //            status = '<span class="label bg-success  btn-block ">'+Translation('عميل دائم')+'  </span>';
          //          }else {
          //            status = '<span class="label bg-violet  btn-block ">'+Translation('زبون اعتيادي')+'  </span>';
          //          }
          //             // return  `<a href='index.php?p=invoice&id=`+row[0]+`'  data-popup='tooltip' data-original-title='Show All Invoices for this Customer'>`+data+`</a>`;
          //             return  status;


          //    },
          //    "targets": 6
          // },


          // {
          //    "render": function(data, type, row){

          //            return  currency_format_display(data);


          //    },
          //    "targets": 6
          // },
            
            
        ],
        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {


            if(   aData[4] == 0 ){
                $(nRow).children().each(function (index, td) {
                    $(this).addClass('warning-active');
                });
            }
        },
        "order": [[0,'desc']],
                "displayLength": 25,
 

        initComplete: function () {
         
        // $("div.datatable-header").append(`<a  style="margin-left:15px;" class="btn bg-info-400"  id="headerBtn" onclick="add_item()"> <i class="icon-file-pdf position-right"></i> Add Category </a>`);   
        if(IS_VIEW==0){
          $("div.datatable-header").append(`<a data-toggle="collapse"
                                      style="margin-right:10px;"
                                      data-target="#add-form-cont"
                                      href="javascript:;"
                                      aria-controls="add-form-cont"
                                      aria-expanded="false"
                                      class="btn btn-primary"
                                      id="add_Item_Btn">
                                        <i class="`+CURRENT_BTN_ICON+`"></i> `+Translation(CURRENT_BTN)+`
                                    </a>`);  
        }


            this.api().columns().every( function() {
                var column = this;
                

            });
        }
    });

    
    table.columns().every( function () {
        var that = this;
        $('input', this.footer()).on('keyup change', function () {
            that.search(this.value).draw();
        });
    });


    // Single row selection
    
    $('.datatable-column-search-inputs tbody').on('click', 'tr', function() {
        if ($(this).hasClass('success')) {
            $(this).removeClass('success');
        }
        else {
            table.$('tr.success').removeClass('success');
            $(this).addClass('success');
        }
    });


         // change filter to top
    $('.datatable-column-search-inputs tfoot tr').insertAfter($('.datatable-column-search-inputs thead tr'))


    $('.dataTables_length select').select2({
        minimumResultsForSearch: Infinity,
        width: 'auto'
    });


});



