I use datatables (/) for creating table with JSON and I have a code:
<script type="text/javascript">
$(document).ready(function() {
$('#example').dataTable( {
"ajax": "objects.txt",
"columns": [
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
]
} );
} );
</script>
<div class="container">
<table id="example" class="table table-striped table-bordered table-responsitive" cellspacing="0" width="100%">
<thead>
<tr>
<th>DAN</th>
<th>Aktivnost</th>
<th>Vreme</th>
<th>Rashodi</th>
<th>Prihodi</th>
<th>Beleske</th>
</tr>
</thead>
<tfoot>
<tr>
<th>DAN</th>
<th>Aktivnost</th>
<th>Vreme</th>
<th>Rashodi</th>
<th>Prihodi</th>
<th>Beleske</th>
</tr>
</tfoot>
</table>
</div>
How I can get name of row and name of column when I click on some cell ? ALso how to get ID of row and ID of column when click on some cell in table?
I use datatables (http://datatables.net/) for creating table with JSON and I have a code:
<script type="text/javascript">
$(document).ready(function() {
$('#example').dataTable( {
"ajax": "objects.txt",
"columns": [
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
]
} );
} );
</script>
<div class="container">
<table id="example" class="table table-striped table-bordered table-responsitive" cellspacing="0" width="100%">
<thead>
<tr>
<th>DAN</th>
<th>Aktivnost</th>
<th>Vreme</th>
<th>Rashodi</th>
<th>Prihodi</th>
<th>Beleske</th>
</tr>
</thead>
<tfoot>
<tr>
<th>DAN</th>
<th>Aktivnost</th>
<th>Vreme</th>
<th>Rashodi</th>
<th>Prihodi</th>
<th>Beleske</th>
</tr>
</tfoot>
</table>
</div>
How I can get name of row and name of column when I click on some cell ? ALso how to get ID of row and ID of column when click on some cell in table?
Share Improve this question asked Oct 30, 2014 at 6:40 James D.James D. 1411 gold badge2 silver badges10 bronze badges1 Answer
Reset to default 13I think this will help you:
Column Selector
Row Selector
OR
You can try this type of code using JQuery:
$('#example tbody').on( 'click', 'td', function () {
alert('Data:'+$(this).html().trim());
alert('Row:'+$(this).parent().find('td').html().trim());
alert('Column:'+$('#example thead tr th').eq($(this).index()).html().trim());
});
This is the fiddle for JQuery code: CLICK HERE