[英]How disable sorting on click on column title but allow for click on arrow in jQuery datatable?
I am rendering a table thanks to jQuery datatable plugin . 由于jQuery datatable插件,我正在渲染一个表。
When you allow sorting on a column , column is sorted if you click on title text or on arrow just near: 当您允许对列进行排序时,如果您单击标题文本或附近的箭头,则会对列进行排序:
Do you know how to disable sorting for click on text but let sorting for click on arrows? 您知道如何禁用对单击文本的排序但如何对单击箭头的排序吗?
I had the same problem and I solve it this way (found the solution here: https://datatables.net/forums/discussion/27035/how-to-disable-sorting-click-event-on-table-header-children ): 我遇到了同样的问题,并且以这种方式解决了这个问题(在这里找到解决方案: https : //datatables.net/forums/discussion/27035/how-to-disable-sorting-click-event-on-table-header-children ):
If you supose the checkbox has the ID #chkbx, this code should work: 如果您认为该复选框的ID为#chkbx,则此代码应该有效:
$('#chkbx').click(function(event){
//Your code here
event.stopPropagation();
});
With the event.stopPropagation() prevent the sorting of the column. 使用event.stopPropagation()防止对列进行排序。
$('#example').dataTable( {
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [ 1 ] }
]
});
1 is your column number (remember the first column is actually 0). 1是您的列号(请记住第一列实际上是0)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.