$(document).ready(function () {
    //Custom ordering tables
    jQuery.fn.dataTableExt.oSort["byDate-pre"] = function(num) {
        let splt = num.split('.')
        text = splt[2]+splt[1]+splt[0]
        return parseInt(text)
    }
    jQuery.fn.dataTableExt.oSort["byDate-asc"] = function(num) {
        let splt = num.split('.')
        text = splt[2]+splt[1]+splt[0]
        return parseInt(text)
    }
    jQuery.fn.dataTableExt.oSort["byDate-desc"] = function(num) {
        let splt = num.split('.')
        text = splt[2]+splt[1]+splt[0]
        return parseInt(text)
    }
    jQuery.fn.dataTableExt.oSort["byUser-pre"] = function(num) {
        if(num == $('#cur_username').val())
            return Infinity;
        else
            return 0;
    }

    var dt = $("#visit_datatable").DataTable({
      "scrollX": true,
      "aoColumnDefs": [{
        "sType": "byUser",
        "bSortable": true,
        "aTargets": [4]
      },
      {
        "sType": "byDate",
        "bSortable": true,
        "aTargets": [2]
      }
      ]
    });

    $('#visit_datatable').DataTable().order([[4, 'pre'],[2, 'pre']]).draw();
    $('#visit_datatable').DataTable().column(0).visible(false);

});
