var tablePostulante = $('#tb-gestionpostulantes').DataTable({
        bFilter: true,
        "bLengthChange": false,
        bInfo: true,
        "searching": true,
        responsive: true,
        "autoWidth": true,
        processing: true,
        serverSide: true,
        ajax: {
            url: url_postulante,
            method: 'GET'
        },
        "language": {
        "lengthMenu": "Mostrar _MENU_ Entradas",
            "zeroRecords": "No se encontraron registros",
            "info": "Mostrando la página _PAGE_ de _PAGES_",
            "infoEmpty": "No hay registros disponibles",
            "infoFiltered": "(filtrado de _MAX_ registros totales)",
            "search": "Buscar: ",
            "paginate": {
            "first": "Primero",
                "last": "Último",
                "next": "Siguiente",
                "previous": "Anterior"
        }
    },
    columns: [
        {
            data:   "id",
            render: function ( data, type, row ) {
                if ( type === 'display' ) {
                    return '<input type="checkbox" name="chkbx-tes" class="editor-active" data-id="'+data+'">';
                }
                return data;
            },
            className: "dt-body-center"
        },
        {data: 'DNI', name: 'DNI'},
        {data: 'Nombre', name: 'Nombre'},
        {data: 'ApellidoP', name: 'ApellidoP'},
        {data: 'ApellidoM', name: 'ApellidoM'}

    ],
    select: {
        style: 'os',
        selector: 'td:not(:last-child)'
    },
    "columnDefs": [
        {
            'targets': 0,
            'searchable': false,
            'orderable': false,
            'width': '1%',
            'className': 'dt-body-center'
        },
        {
            "targets": [ 2 ],
            "visible": true,
            "searchable": true
        }
    ],
    "order": [],
    initComplete: function () {
        $('#text-filter').on('keyup',function(){
            tablePostulante.column(2).search($(this).val()).draw();
        });
    },
    rowCallback: function ( row, data, index ) {

        var rowId = data["id"];
        if($.inArray(rowId, rows_selected_postulante) !== -1){
            $(row).find('input[type="checkbox"]').prop('checked', true);
            $(row).addClass('selected');
        }
    }
});

$('#tb-gestionpostulantes tbody').on('click', 'input[type="checkbox"]', function(e){
    var $row = $(this).closest('tr');
    var data = tablePostulante.row($row).data();
    var rowId = data["id"];
    var index = $.inArray(rowId, rows_selected_postulante);
    if(this.checked && index === -1){
        rows_selected_postulante.push(rowId);

    } else if (!this.checked && index !== -1){
        rows_selected_postulante.splice(index, 1);
    }
    if(this.checked){
        $row.addClass('selected');
    } else {
        $row.removeClass('selected');
    }
    updateDataTableSelectAllCtrl(tablePostulante);
    e.stopPropagation();
});

$('#tb-gestionpagos').on('click', 'tbody td, thead th:first-child', function(e){
    $(this).parent().find('input[type="checkbox"]').trigger('click');
});

$('thead input[name="select_all"]', tablePostulante.table().container()).on('click', function(e){
    if(this.checked){
        $('#tb-gestionpostulantes tbody input[type="checkbox"]:not(:checked)').trigger('click');
    } else {
        $('#tb-gestionpostulantes tbody input[type="checkbox"]:checked').trigger('click');
    }

    e.stopPropagation();
});

tablePostulante.on('draw', function(){
    updateDataTableSelectAllCtrl(tablePostulante);
});