function loadData() {
	var oTable = $('#contact').DataTable( {
	"serverSide": true,
	  "ajax": {
		"url": "/contacts/list",
		"type": "POST",
	  },
	"ordering": false,
	"bInfo": false,
	"bAutoWidth ": false,
	buttons: [
		{ extend: 'print', className: 'btn dark btn-outline' },
		{ extend: 'excel', className: 'btn yellow btn-outline ' },
		{ extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
	],
	"lengthMenu": [ [10, 25, 50,100,99999999], [10, 25, 50,100, "All"] ],
	
	"bLengthChange": false,
	});
	$('.search-input-text').on( 'keyup click change', function () {   // for text boxes
		var i =$(this).attr('data-column');  // getting column index
		var v =$(this).val();  // getting search input value
		oTable.columns(i).search(v).draw();
	} );
	$('.search-input-select').on( 'change', function () {   // for select box
		var i =$(this).attr('data-column');  
		var v =$(this).val();  
		oTable.columns(i).search(v).draw();
	} );
	$('.filter-cancel').on( 'click', function () {   // for select box
		$('.search-input-text').val('');
		$('.search-input-select').val('');
		$('.search-input-text').trigger('change');
		$('.search-input-select').trigger('change');
		
		oTable.draw();
	} );
	$("#contact_filter").css("display","none"); 

}
$(document).ready(function() {
    loadData(1);    
	$(document).on("click",".view-detail",function() {
			var id = $(this).data('id');
			var dataStringg = 'id='+id;
			$.ajax({
				type: "POST",
				url: "/contacts/get-detail",				
				cache: false,
				data: dataStringg,
				success: function(data) {
					$("#getCode").html(data);
					jQuery("#user-detail").modal('show');
				}
			});
		}); 
	$(document).on("click",".view-detail-add",function() {
			var id = $(this).data('id');
			var dataStringg = 'id='+id;
			$.ajax({
				type: "POST",
				url: "/contacts/get-detail",				
				cache: false,
				data: dataStringg,
				success: function(data) {
					$("#getCode2").html(data);
				}
			});
		}); 
	$(document).on("click",".add-user",function() {
			jQuery("#add-user").modal('show');
		
		});
	$(document).on("click",".add",function() {
			var id = $(this).data('id');
			var dataStringg = 'id='+id;
			$.ajax({
				type: "POST",
				url: "/contacts/add-contact",				
				cache: false,
				data: dataStringg,
                beforeSend: function(){ 
					jQuery("#add-user").modal('hide');
                    $("#submitprofile").hide();
                    $("#waiting").show();
                    $("#suksesupdate").hide();
                    $("#gagalupdate").hide();
                },
                complete: function(e, xhr, settings){
                    if(e.status === 200){
                        $("#submitprofile").show();
                        $("#waiting").hide();
                        $("#suksesupdate").show();
						location.reload();
                        //$("#gagalupdate").hide();
                    }else{
                        $("#submitprofile").show();
                        $("#waiting").hide();
                        //$("#suksesupdate").show();
                        $("#gagalupdate").show();
						location.reload();
                    }
                }
			});
		
		});
		
		$(document).on("click",".add-company",function() {
			var id = $(this).data('id');
			var dataStringg = 'id='+id;
			$.ajax({
				type: "POST",
				url: "/companies/add-company",				
				cache: false,
				data: dataStringg,
                beforeSend: function(){ 
					jQuery("#add-user").modal('hide');
                    $("#submitprofile").hide();
                    $("#waiting").show();
                    $("#suksesupdate").hide();
                    $("#gagalupdate").hide();
                },
                complete: function(e, xhr, settings){
                    if(e.status === 200){
                        $("#submitprofile").show();
                        $("#waiting").hide();
                        $("#suksesupdate").show();
						location.reload();
                        //$("#gagalupdate").hide();
                    }else{
                        $("#submitprofile").show();
                        $("#waiting").hide();
                        //$("#suksesupdate").show();
                        $("#gagalupdate").show();
						location.reload();
                    }
                }
			});
		
		});
		
});
jQuery(document).ready(function() {    
   // Example #3
        var custom = new Bloodhound({
          datumTokenizer: function(d) { return d.tokens; },
          queryTokenizer: Bloodhound.tokenizers.whitespace,
          remote: {
				url: '/contacts/user-list?query=%QUERY',
				wildcard: '%QUERY'
			} 
        });
         
        custom.initialize();
         
        if (App.isRTL()) {
          $('#typeahead_example_modal_3').attr("dir", "rtl");  
        }
        $('#typeahead_example_modal_3').typeahead(null, {
          name: 'datypeahead_example_modal_3',
          displayKey: 'value',
          hint: (App.isRTL() ? false : true),
          source: custom.ttAdapter(),
          templates: {
            suggestion: Handlebars.compile([
              '<a class="view-detail-add" data-id ="{{desc}}">',
				  '<div class="media">',
						'<div class="pull-left">',
							'<div class="media-object">',
								'<img src="{{img}}" width="50" height="50"/>',
							'</div>',
						'</div>',
						'<div class="media-body">',
							'<h4 class="media-heading">{{value}}</h4>',
						'</div>',
				  '</div>',
			  '</a>',
            ].join(''))
          }
        });
});