问题描述
我已经完成了一个数据表并自定义了它的数据,但是当我单击第一列上的按钮时,它仅在第一页上起作用,而不能在其他前进页上单击.
I have done a datatable and custom it's data but when i click the button on the first column, it only works on the first page and cannot click on other forward pages.
$('#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"},{},{},{},{},{},{},{},{}
]
} );
但是当在实时模式下使用点击功能时,它仍然无法工作
BUT when for the click function in live mode, it still cannot work
$('#tbl tbody tr #edit_current_product').delegate('a', 'click', function () {
.......
} );
推荐答案
id
必须是唯一的.我们不知道您的标记,但是
id
's must be unique. We dont know your markup but
$('#tbl tbody tr #edit_current_product').delegate('a', 'click', function ()
似乎完全错误.您有多个具有相同ID #edit_current_product
的<a>
,或者实际上发生了正确的事情,您已经离开了显示#edit_current_product
的页面.
seems utterly wrong. Either you have multiple <a>
's with the same id #edit_current_product
or the right thing actually happens, you have paginated away from the page where #edit_current_product
is present.
我想您真正想要的是
$('#tbl').on('click', 'tbody tr a', function()
或使用类代替id
$('#tbl').on('click', 'tbody tr .edit_current_product', function()
顺便说一句,为什么
BTW, why
"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] }
]
这篇关于分页后DataTable无法单击该按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!