I\'m generating a DataTable with a javascript data source. The data is returned from an ajax call to nodejs which queries SQL Server DB table and returns 2 columns,
I have a sort of hackish yet applicable and simple solution. The thing to note is my code DOES allow usage of the DataTables data()
method and also that this is more of a solution for anybody receiving HTML code instead of inner text from each cell of a row, rather than trying to get the value of an input
text box. The row clicked on returns an array through data()
. Each cell of the row is wrapped in a span
so any plaintext/non-HTML strings inside a td
can be rendered as HTML elements and therefore be recognized by the jQuery text()
method:
$('#mytable tbody').on('click', 'tr', function (e) {
var rowArray = aTable.row(this).data();
var colAchange = $('').html(rowArray[0]).text();
var colBchange = $('').html(rowArray[1]).text();
});
JSFiddle: https://jsfiddle.net/nyv7j6h8/