简体   繁体   中英

How do I get the value from <input type=date> inside a cell in jQuery DataTables?

I have a dynamically created (when I click on the cell) <input type=date> inside a cell of a DataTable.

I can select the date and looks good, now I get all the data in the table iterating each row because I process the data for every row, that works fine too, the problem is when I want to get the value from those inputs.

I tried with data() and node() but the value isn't shown on the HTML which I found out that was the way it's supposed to be, so I can't get it from the HTML, so I tried with the following code and it says it's undefined.

table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
        // Tried this - return undefined

        var node = this.node();     
        alert(node.cells[0].value);// The typeof(node.cells[0]) is object HTMLTableCellElement


        // also this - here shows the HTML without the updated date
        var data = this.data();     
        alert(data);

});

Any ideas?

SOLUTION

Use the code below to access value of input inside the cell in the first column ( column: 0 ).

var table = $('#example').DataTable();

table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {       
    var cell = table.cell({ row: rowIdx, column: 0 }).node();

    console.log($('input', cell).val());
});

DEMO

See this jsFiddle for code and demonstration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM