jquery datatable get row data by index code example
Example 1: datatable get row data
var table = $('#example').DataTable();
$('#example tbody').on( 'click', 'tr', function () {
console.log( table.row( this ).data() );
} );
Example 2: get table row data jquery
$("document").ready(function() {
var tb = $('.layui-table:eq(0) tbody');
var size = tb.find("tr").length;
console.log("Number of rows : " + size);
tb.find("tr").each(function(index, element) {
var colSize = $(element).find('td').length;
console.log(" Number of cols in row " + (index + 1) + " : " + colSize);
$(element).find('td').each(function(index, element) {
var colVal = $(element).text();
console.log(" Value in col " + (index + 1) + " : " + colVal.trim());
});
});
});
Example 3: jtable get get row
public String[] getRowAt(int row) {
String[] result = new String[colNumber];
for (int i = 0; i < colNumber; i++) {
result[i] = table.getModel().getValueAt(row, col);
}
return result;
}
Example 4: get table row data jquery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table cellspacing="0" cellpadding="0" border="0" class="layui-table">
<tbody>
<tr data-index="0" class="">
<td data-field="sid" data-content="123456">
<div class="layui-table-cell laytable-cell-1-sid"> 123456 </div>
</td>
<td>
<div></div>
</td>
</tr>
<tr data-index="1" class="">
<td data-field="sid" data-content="100012">
<div class="layui-table-cell laytable-cell-1-sid"> 100012 </div>
</td>
<td>
<div></div>
</td>
</tr>
</tbody>
</table>