数据表行单击事件不起作用 [英] Data table row click event not working
问题描述
我使用coldfusion将数据从数据库中提取到dataTable中,当我点击数据表中的一行并触发事件时,我希望这样,以便该行的详细信息可以显示在同一页面上的div中。
I am pulling data from a database using coldfusion into a dataTable and I would like that when I click on a row in the datatable and event is fired which so that the details of that row can be displayed in divs on the same page.
以下是我正在使用的代码,但它不起作用,如果有人能给我一个有效的例子,我将不胜感激
Below is the code I am using but it is not working, I would appreciate it if someone could give me an example that works
我收到以下错误消息:
错误 - 无法读取未定义的属性'_aData'
Error - Cannot read property '_aData' of undefined
$(document).ready(function() {
var table = $('#datatable-buttons').DataTable();
$('#datatable-buttons tbody').on('click', 'tr', function () {
var data = table.row( this ).data();
// alert( 'You clicked on '+data[0]+'\'s row' );
alert("table click"+data[0]);
} );
} );
推荐答案
尝试解除按钮事件的绑定分配它们:只需在行单击之前添加以下行:
Try unbinding the event for your buttons before you re-assign them: just add the following line before the row click:
$('#datatable-buttons tbody').off('click');
所以更改的代码是:
$(document).ready(function() {
var table = $('#datatable-buttons').DataTable();
$('#datatable-buttons tbody').off('click');
$('#datatable-buttons tbody').on('click', 'tr', function () {
var data = table.row( this ).data();
// alert( 'You clicked on '+data[0]+'\'s row' );
alert("table click"+data[0]);
} );
});
这篇关于数据表行单击事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!