function loadData() {
	var oTable = $('#example').DataTable( {
	"serverSide": true,
	  "ajax": {
		"url": "/user-management/list",
		"type": "POST",
	  },
	"lengthMenu": [ [10, 25, 50,100,99999999], [10, 25, 50,100, "All"] ],
	"order": [
		[ 0, 'desc' ]
	],	
	"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();
	} );
	$("#example_filter").css("display","none"); 

}
function block(id){
   $.ajax({
                type: "POST",
                url: "/user-management/block",
                data: "id="+id,
                cache: false,
                success: function(msg)
                        {
                           window.location.href = "/user-management";
                        }
                
            });
}
function unblock(id){
    $.ajax({
                type: "POST",
                url: "/user-management/unblock",
                data: "id="+id,
                cache: false,
                success: function(msg)
                        {
                           window.location.href = "/user-management";
                        }
                
            });
}
function godMode(id){
   $.ajax({
                type: "POST",
                url: "/user-management/godmode",
                data: "id="+id,
                cache: false,
                success: function(msg)
                        {
                           window.location.href = "/dashboard";
                        }
                
            });
}
$(document).ready(function() {
    loadData(1);
    $(document).on("click",".ban",function() {
		$(this).html("PLEASE WAIT..")
		$(this).attr("disabled", true);
		var id = $(this).attr('data-id');
		block(id);
    }); 
    $(document).on("click",".unban",function() {
		$(this).html("PLEASE WAIT..")
		$(this).attr("disabled", true);
		var id = $(this).attr('data-id');
		unblock(id);
    }); 
    $(document).on("click",".godmode",function() {
		$(this).html("PLEASE WAIT..")
		$(this).attr("disabled", true);
		var id = $(this).attr('data-id');
		godMode(id);
    }); 

});