StackOverflow - Datat Table.js How to Check Column Fixed or not?
by Muhammad Mushtaq Sheikh
HTML
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
<script src="https://cdn.datatables.net/fixedcolumns/3.2.2/js/dataTables.fixedColumns.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/fixedcolumns/3.2.2/css/fixedColumns.dataTables.min.css">
<table id="example" class="stripe row-border order-column" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<button id="btnGetFixedCol">Get Fixed Col</button>
</td>
<td>Tiger</td>
<td>Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
<td>5421</td>
<td>[email protected]</td>
</tr>
<tr>
<td>
<button id="btnGetFixedCol">Get Fixed Col</button>
</td>
<td>Garrett</td>
<td>Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>$170,750</td>
<td>8422</td>
<td>[email protected]</td>
</tr>
<tr>
<td>
<button id="btnGetFixedCol">Get Fixed Col</button>
</td>
<td>Ashton</td>
<td>Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$86,000</td>
<td>1562</td>
<td>[email protected]</td>
</tr>
<tr>
<td>
<button id="btnGetFixedCol">Get Fixed Col</button>
</td>
<td>Cedric</td>
<td>Kelly</td>
<td>Senior Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>2012/03/29</td>
...
JavaScript
var table;
$(document).ready(function() {
table = $('#example').DataTable({
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: true,
fixedColumns: {
leftColumns: 2
}
});
});
$('body').on('click', '#btnGetFixedCol', function() {
var tr = $(this).closest("tr");
var rowindex = table.row(tr).index()
console.log("Row Index : " + rowindex);
var tdLeft = $(".DTFC_LeftBodyLiner table.DTFC_Cloned").find("td[data-dt-row='" + rowindex + "']");
for (var i = 0; i < tdLeft.length; i++) {
var tdIndex = parseInt($(tdLeft[i]).attr('data-dt-column'));
console.log("td Index : " + tdIndex)
var tdData = table.cell(tdLeft[i]).data();
console.log("tdData : " + tdData);
}
})