Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  167] [ 6]  / answers: 1 / hits: 25179  / 10 Years ago, thu, october 30, 2014, 12:00:00

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?


More From » jquery

 Answers
12

I 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


[#68968] Monday, October 27, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylanalis

Total Points: 438
Total Questions: 85
Total Answers: 102

Location: Barbados
Member since Sun, Nov 27, 2022
1 Year ago
kylanalis questions
Sat, Oct 2, 21, 00:00, 3 Years ago
Tue, Oct 13, 20, 00:00, 4 Years ago
Thu, Feb 13, 20, 00:00, 4 Years ago
Tue, Jan 7, 20, 00:00, 4 Years ago
;