[英]jQuery button doesn't work after sorting datatable
I have a jQuery function which looks like this: 我有一个jQuery函数,如下所示:
function unlock_reservation_columns(resid) {
$('.unlock-columns').click( function(event) {
event.preventDefault();
$(this).closest('tr').find('.columns-locked').removeClass('columns-locked');
$(this).html('<i class="fa fa-lock"></i> Lock Columns');
$(this).attr('class', 'lock-columns');
new PNotify({
title: 'We have unlocked this reservation..',
text: 'Reservation Unlocked',
type: 'success'
});
var url = $(this).attr("href");
var url_id = url.replace(/[^0-9]/g, '')
$.get(url, function (data) {
var confirm_changes = confirm('Do you wish to edit unlocked information?');
if (confirm_changes) {
window.location.href = '/reservations/database/edit/' + url_id;
}
else {
location.reload()
return false;
}
});
});
});
<a class="unlock-columns" href="<?php echo $row->unlock_url; ?>"><i class="fa fa-unlock"></i> Unlock Columns</a>
The button "unlock-columns" is located inside a Datatable custom column. “unlock-columns”按钮位于Datatable自定义列中。 Now when the page is only initialized this button works fine.
现在,只有初始化页面时,此按钮才能正常工作。 After i sort something in the table.
我在表格中排序后。 the (data-order-by) and click the button it doesn't work.. like after sorting it stops working.
(数据顺序)并单击它不起作用的按钮..就像排序后它停止工作。 any ideas why?
任何想法为什么?
Use a delegated event handler 使用委派的事件处理程序
$('#tableId').on('click', '.unlock-columns', function(event) {
instead. 代替。 As it is now you only attach the click handler to visible rows upon initialisation, not rows injected later on (as when you are paginating, sorting etc).
因为现在你只是在初始化时将点击处理程序附加到可见行,而不是稍后注入的行(如分页,排序等)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.