Hi, I have a datatable with checkbox, I want to send an MVC controller, but it doesn't recognize th

Hi, I have a datatable with checkbox, I want to send an MVC controller, but it doesn't recognize th

ocardonac3ocardonac3 Posts: 1Questions: 1Answers: 0
edited September 2019 in Free community support

Fill my table

function fill(response) {
     table =  $('#datatable-prueba-checkbox').DataTable({
        "destroy": true, 
        "data": response,
        "ordering": false,
        "columns": [            
            {                
                data: "seleccion",                
                render: function (data, type, row) {
                    if (type === 'display') {
                        if (data == true) {                            
                            return '<input type="checkbox" id="select ' + row.idSubCategoria + '"  value=' + row.idSubCategoria + ' class="icheckbox_flat-green all_asignado change" checked="checked">';
                        }                        
                        return '<input type="checkbox" id="select ' + row.idSubCategoria + ' "  value=' + row.idSubCategoria + ' class="icheckbox_flat-green all_asignado change">';
                    }
                    return data;
                }               
            } ,  
            { data: "descripcion" },
            {
                data: "es_jefe",
                render: function (data, type, row) {
                    if (type === 'display') {                        
                        if (data == true) {
                            return '<input type="checkbox" id=' + row.idSubCategoria + ' value=' + row.idSubCategoria + ' class="icheckbox_flat-green all_esjefe change" checked="checked">';
                        }
                        return '<input type="checkbox" id=' + row.idSubCategoria + ' value=' + row.idSubCategoria + ' class="icheckbox_flat-green all_esjefe change">';
                    }
                    return data;
                }               
            }   
        ],
         select: {
             style: 'os',
             selector: 'td:not(:last-child)' // no row selection on last column
         }       
    });    
}

Convert to object ------

function convertTableToArrayObject() {
    var Object = [];
    var table = $('#datatable-prueba-checkbox').DataTable();
    var data = table.rows().data();

    for (var i = 0; i < data.length; i++) {
        Object.push(data[i]);         
    }         
    return Object;
}

Save Function ----------------

function Guardar() {
    var usuario = $("#codigo_usuario").val();   
    var rows = convertTableToArrayObject();
 
    //var rows = JSON.stringify(table)
    $.ajax({
        type: "POST",
        dastaType: "JSON",
        url: "/OTS_Usuario_SubCategoria_FE/Save?usuario=" + usuario,
        data: { ListJson: rows },
        success: function (result) {
            if (result) {
                //window.location.href = "/OTS_Usuario_SubCategoria_FE/Index";
                TraePermisos(usuario);
            } else {
                $("#MyModal").modal("hide");
                Mensaje(2, "Hubo un error al guardar, intente de nuevo o comuniquese con el Administrador del sistema!");
            }
        }
    })
}

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @ocardonac3 ,

    That's a lot of code there. Can you give more details, please, such as any errors you're seeing, or what exactly "doesn't recognise the th"? Can you also link to a page showing the issue, please.

    Cheers,

    Colin

This discussion has been closed.