Input values

Input values

atnozatnoz Posts: 5Questions: 1Answers: 0
edited June 2014 in Free community support

Im will try be more clear. Im really novice.

How can i get the updated value from inputs after change it?

http://live.datatables.net/vogarad/1/edit

Thanks

MM

$(document).ready(function(){

    var dataSet = [
    
    ["A", 1, 2, 3, 4, '<input type="text" id="in1" name="in1" value=50 "/>', '<input type="checkbox" id="ck1" name="ck1" checked="checked" />'],
            
    ["B", 5, 6, 7, 8, '<input type="text" id="in2" name="in2" value=10 "/>', '<input type="checkbox" id="ck2" name="ck2" checked="checked" />'],
        
    ["C", 1, 3, 6, 8, '<input type="text" id="in3" name="in3" value=5 "/>', '<input type="checkbox" id="ck3" name="ck3" checked="checked" />']
        
    ];

    $('#place').html('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>');
 
    var oTable = $('#example').dataTable({
        "data": dataSet,
        "columns": [
            { "title": "TYPE" },
            { "title": "C1" },
            { "title": "C2" },
            { "title": "C3" },
            { "title": "C4" },
            { "title": "C5" },
            { "title": "YES" }
            ]
        
    });   
    
    $("#dump").click( function(){
        var ckdata = $('input:checked', oTable.fnGetData() );
        console.log(ckdata);
    });

});

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Using the old API - as you are, you can use the $ method: oTable.$('#in1').val()

    Allan

  • atnozatnoz Posts: 5Questions: 1Answers: 0
    edited July 2014

    Cool! I changed the code. Its now updating the text inputs and geting the values
    BUT the checkbox inputs state dont update and im getting empty elements in array. :(

    [""][""][""][""][""]["50"]["on"] -> Should be ["A"]["1"]["2"]["3"]["4"]["50"]["on"]

    [""][""][""][""][""]["10"]["on"]

    [""][""][""][""][""]["5"]["on"]

                    $("#dump").click( function(){
    
                        var nlines = $(oTable.fnGetNodes()).length;
                        var ncols = $(oTable.fnGetNodes(0)).find("td").length;              
                        
                        for(var i=0; i<nlines; i++){
                            for(var j=0; j<ncols; j++){
                            
                            
                            var alldata = [];
                            var z = oTable.fnGetNodes()[i].cells[j].childNodes[0];
                            alldata.push(  oTable.$(z).val()  );
                            console.log(alldata);
                        
                            }
                        }
                    });
    

    When it was :

                    $("#dump").click( function(){
                        var items = oTable.fnGetNodes();
                        for ( var i=0 ; i<items.length ; i++ ) {
                        var alldata = oTable.fnGetData(i);
                        console.log(alldata);
                        }
                                     });
    

    All inputs dont updated, got this ugly tag and not only the values.

    ["A", 1, 2, 3, 4, "<input type="text" id="in1" name="in1" value=50 "/>", "<input type="checkbox" id="ck1" name="ck1" checked="checked" />"]

    Im pulling my hairs (giggles).

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    We'd need a link to a test case showing the problem please.

    Allan

  • atnozatnoz Posts: 5Questions: 1Answers: 0

    Here Allan:

    http://live.datatables.net/vogarad/3/edit

    Dump 1 and 2 buttons. Check the console please.

    Feel free to modify.

  • atnozatnoz Posts: 5Questions: 1Answers: 0

    I spent all day playing around but still dont found a full solution.
    Anyone testing?

  • DaimianDaimian Posts: 62Questions: 1Answers: 15
    Answer ✓

    Here you go, not pretty but it works. Check Dump1
    http://live.datatables.net/vogarad/4/edit

  • atnozatnoz Posts: 5Questions: 1Answers: 0
    edited July 2014

    God... I see now. One inside other...

    alldata.push(  oTable.$(z).is("input") ? (oTable.$(z).attr("type") == "checkbox" ? oTable.$(z)[0].checked : oTable.$(z).val()) : oTable.$(z).text()  );
    

    Thank you very much. I really appreciated.

This discussion has been closed.