Table header with JavaScript

0

Hello, I can not find a way to paint a header dynamically with Java Script, My JS filters by client and it paints the table, but it only paints me the data and I can not put the header because depending on the client it can vary by I do not paint it directly in HTML. This is my script:

window.RefaccionesE = {
 formClienteId: "FormRefaccionesCaptura",
 tblRefacccionesId: "",
 ClienteId: ""
};

window.Refacciones = {
init: function (data) {
    $.extend(RefaccionesE, data);

    $("body").on("change", "#ClienteId", Refacciones.SelectedClient);
    RefaccionesE.tblRefacccionesId = $('tblRefacccionesId').DataTable({ dom: 'r' });

},
SelectedClient: function () {

    RefaccionesE.ClienteId = $("#ClienteId").val();
    Refacciones.getRefacciones();
},


//Obtiene la informacion para la tabla refacciones
getRefacciones: function () {
    General.ajax({
        url: RefaccionesE.uriRefacciones,
        data: {
            ClienteId: RefaccionesE.ClienteId
        },
        type: Method.Post,
        Callback: Refacciones.CallBackGetListaRefacciones
    });

},
CallBackGetListaRefacciones: function (data) {
    var dta = data.aaData.Model;
    Loading.ShowLoader();

    RefaccionesE.tblRefacccionesId.destroy();

    if(dta !=null)
        dta.forEach(Refacciones.InsertaRenglon)

    RefaccionesE.tblRefacccionesId = $('#tblRefacccionesId').DataTable(

        {
            language: Grid.languageDefault,

            dom: 'ft<"lengt"l><"info"i><"pagination"p>',
        });
    Loading.HideLoader();

    console.log(data);
},

// Dibujar encabezado


//Dibujamos tabla 
InsertaRenglon: function (item, index, arr) {
    var table = document.getElementById("tblRefacccionesId");
    var row = table.tBodies[0].insertRow();
    row.id = "tc" + item.NumeroDeParte;
    var cell0 = row.insertCell(0);
    var cell1 = row.insertCell(1);
    var cell2 = row.insertCell(2);
    var cell3 = row.insertCell(3);
    var cell4 = row.insertCell(4);
    var cell5 = row.insertCell(5);
    var cell6 = row.insertCell(6);

    cell0.innerHTML = item.NumeroDeParte;
    cell1.innerHTML = item.Descripcion;
    cell2.innerHTML = item.W1;
    cell3.innerHTML = item.W2;
    cell4.innerHTML = item.W3;
    cell5.innerHTML = item.W4;
    cell6.innerHTML = item.W5;

},

}

I would appreciate your help, they told me that I could do it with another function but I can not find a clear example on the internet.

    
asked by Ch3vi 30.05.2018 в 00:19
source

0 answers