DataTable cannot click the button after pagination

本秂侑毒 提交于 2021-01-28 12:11:02

问题


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 () {
    ....... 
} );

回答1:


id's must be unique. We dont know your markup but

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

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.

I guess that what you really want is

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

or use a class instead of an id

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

BTW, why

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

you just need

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


来源:https://stackoverflow.com/questions/33996021/datatable-cannot-click-the-button-after-pagination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!