解决方案
您正在使用DataTables 1.10.8 . 在此版本(1.10.7及更早版本)之前,有一些带有fnCellRender选项的TableTools可以帮助您完成所需的操作 . 从1.10.8开始,TableTools扩展已被Buttons扩展名替换 .
使用按钮扩展,您可以使用exportOptions并告诉DataTables您想要用于排序的数据( orthogonal: 'sort' ) . 然后,您需要定义render函数并在执行排序时返回适当的数据( type === 'sort' ) .
作为副作用,这将使您的复选框列也可以排序 .
var table = $('#example1').DataTable({
dom : 'Bfrtlip',
buttons: [
{
extend: 'excel',
exportOptions: {
orthogonal: 'sort'
}
}
],
columnDefs: [{
targets:[0,5],
render: function(data, type, row, meta){
if(type === 'sort'){
var $input = $(data).find('input[type="checkbox"]').addBack();
data = ($input.prop('checked')) ? "1" : "0";
}
return data;
}
}]
});
演示