分页后,DataTable无法单击该按钮

时间:2015-11-30 10:09:51

标签: javascript jquery datatables

我已经完成了一个数据表并自定义了它的数据,但是当我点击第一列上的按钮时,它只能在第一页上运行,而不能点击其他正向页面。

$('#tbl').DataTable( {
   responsive: true,
   data: data1,
   autoWidth: false,
   "order": [[ 7, "asc" ]],
   "iDisplayLength": 5,
   "pagingType": "full_numbers",
   "dom": '<"top">rt<"bottom"p><"clear">',
   "oLanguage": {
        "sEmptyTable":     "Not Record"
    },
    "columnDefs": [
        { "visible": false,  "targets": [ 6,7,8 ] }
    ],
    "columns": [
        {},{"sClass": "dt-body-justify"},{},{},{},{},{},{},{},{}
    ]
} );

但是对于实时模式下的点击功能,它仍然无法正常工作

$('#tbl tbody tr #edit_current_product').delegate('a', 'click', function () {
    ....... 
} );

1 个答案:

答案 0 :(得分:1)

id必须是唯一的。我们不知道您的标记,但

$('#tbl tbody tr #edit_current_product').delegate('a', 'click', function () 

似乎完全错了。您有多个<a>具有相同的ID #edit_current_product或者实际发生了正确的事情,您已经远离#edit_current_product所在的页面分页。

我猜你真正想要的是

$('#tbl').on('click', 'tbody tr a', function() 

或使用课程代替id

$('#tbl').on('click', 'tbody tr .edit_current_product', function() 

BTW,为什么

"columnDefs": [
    { "visible": false,  "targets": [ 6,7,8 ] }
],
"columns": [
    {},{"sClass": "dt-body-justify"},{},{},{},{},{},{},{},{}
]

你只需要

"columnDefs": [
    { "visible": false,  "targets": [ 6,7,8 ] },
    { "sClass": "dt-body-justify", targets : [1] }
]
相关问题