Get the value of a textbox inside a datatable

Get the value of a textbox inside a datatable

MMarMMar Posts: 2Questions: 0Answers: 0
edited March 2015 in Free community support

Hi everyone,

I have a datatable with 2 columns with a textbox and I don't manage to get the value. Here's thecode:

       var nCloneTh3 = document.createElement('th');
        var nCloneTd3 = document.createElement('td');
        nCloneTd3.innerHTML = '<input type="checkbox" id="chkEsOT">';
        nCloneTd3.className = "center";
        $('#GVEPtesEntregadoJUST thead tr').each(function () {
            this.insertBefore(nCloneTh3, this.childNodes[0]);
        });
        $('#GVEPtesEntregadoJUST tbody tr').each(function () {
            this.insertBefore(nCloneTd3.cloneNode(true), this.childNodes[0]);
        });


        var nCloneTh2 = document.createElement('th');
        var nCloneTd2 = document.createElement('td');
        nCloneTd2.innerHTML = '<input type="text" with="100%" id="txtCli" >';
        nCloneTd2.className = "center";
        $('#GVEPtesEntregadoJUST thead tr').each(function () {
            this.insertBefore(nCloneTh2, this.childNodes[0]);
        });
        $('#GVEPtesEntregadoJUST tbody tr').each(function () {
            this.insertBefore(nCloneTd2.cloneNode(true), this.childNodes[0]);
        });

        var nCloneTh = document.createElement('th');
        var nCloneTd = document.createElement('td');
        nCloneTd.innerHTML = '<input type="text" with="100%"  id="txtNumOTTicket">';
        nCloneTd.className = "center";
        $('#GVEPtesEntregadoJUST thead tr').each(function () {
            this.insertBefore(nCloneTh, this.childNodes[0]);
        });
        $('#GVEPtesEntregadoJUST tbody tr').each(function () {
            this.insertBefore(nCloneTd.cloneNode(true), this.childNodes[0]);
        });


        var otablaEPtesEntregadoJUST = $('#GVEPtesEntregadoJUST').dataTable({
            "bRetrieve": true,
            "bDestroy": true,
            "bJQueryUI": true,
            "bStateSave": true,
            "iDisplayLength": 10,
            "sPaginationType": "full_numbers",
            "sScrollY": "100%",
            "sDom": '<"H"fl>t<"F"ipT>',
            "aoColumnDefs": [
                { "bSortable": false, "aTargets": [0,1,2,3,4,5] },
                { "sTitle": "OT/Ticket",  "sName": "nOTTicket",   "aTargets": [ 0 ] },
                { "sTitle": "Cliente",  "sName": "nCliente",   "aTargets": [ 1 ] },
                { "sTitle": "Es OT",  "sName": "nEsOT",   "aTargets": [ 2 ] }
                ],
            "oTableTools": {
                "sSwfPath": "DataTables/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf",
                "aButtons": [
                {
                    "sExtends": "xls",
                    "sToolTip": "Guardar como XLS",
                    "mColumns": "visible",
                    "bSelectedOnly": true
                }]}

        });

To get the values I want to use a button to read all the rows.

Any idea?

Replies

  • MMarMMar Posts: 2Questions: 0Answers: 0
    edited March 2015

    Here's the solution:

    $('#btnJustificar').click( function() {
    var numero = $('#GVEPtesEntregadoJUST').dataTable().fnGetNodes().length;
    var vCliente;
    var vOTTicket;
    var vEsOT;
    if (numero != 0) {

                     for (i = 0; i < numero; i++) {
    
    
                        $("#GVEPtesEntregadoJUST tr:eq(" + i + ") input:text:eq(0)").each(function() {
                            //inputs.push ( [this.id, this.value] );
                            if (this.value != ''){
                                 vOTTicket=this.value;
                            }
                        });
                        $("#GVEPtesEntregadoJUST tr:eq(" + i + ") input:text:eq(1)").each(function() {
                            if (this.value != ''){
                                vCliente=this.value;
                            }
                        });
    
                        .............
    
    
                        }
    
    
    
    
                     }
                 }
    
                return false;
            } );
    
This discussion has been closed.