admin管理员组文章数量:1415100
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
1 Answer
Reset to default 5SOLUTION
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.
版权声明:本文标题:javascript - How do I get the value from <input type=date> inside a cell in jQuery DataTables? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745178340a2646349.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论