如何在单击列标题时禁用排序,但允许在jQuery数据表中单击箭头?

Viv*_*ipo 2 javascript sorting jquery datatables jquery-datatables

我正在渲染一个表,感谢jQuery datatable插件.

当您允许对列进行排序时,如果单击标题文本或刚好靠近箭头,则会对列进行排序:

在此输入图像描述

你知道如何禁用点击文本的排序,但让点击箭头排序?

小智 5

我有同样的问题,我这样解决(在这里找到解决方案:https://datatables.net/forums/discussion/27035/how-to-disable-sorting-click-event-on-table-header-children):

如果您设置了ID为#chkbx的复选框,则此代码应该有效:

$('#chkbx').click(function(event){

  //Your code here

  event.stopPropagation();
});
Run Code Online (Sandbox Code Playgroud)

使用event.stopPropagation()可以阻止列的排序.