Get Datatables cell value that is input text field

前端 未结 2 344
[愿得一人]
[愿得一人] 2021-01-13 06:48

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,

2条回答
  •  再見小時候
    2021-01-13 07:07

    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/

提交回复
热议问题