最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Oct 2, 2015 at 17:35 Gyrocode. 59k16 gold badges157 silver badges192 bronze badges asked Oct 2, 2015 at 17:12 rodzunrodzun 1372 gold badges3 silver badges7 bronze badges 1
  • it's not the TD that has the value, it's the input, use node.cells[0] .children[0] .value – dandavis Commented Oct 2, 2015 at 18:22
Add a ment  | 

1 Answer 1

Reset to default 5

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.

发布评论

评论列表(0)

  1. 暂无评论