【发布时间】:2014-08-29 06:15:22
【问题描述】:
dtTable = $("table.tablesorter").DataTable({
bDestroy: true,
bSort: false,
bFilter: false,
bLengthChange: true,
"aLengthMenu": [
[5, 15, 25, 50, -1],
[5, 15, 25, 50, "All"] // change per page values here
],
"iDisplayLength": recordsPerPage,
"sDom": "t<'row-fluid'<'m-wrap span3 customTableInfo'i><'m-wrap span4'p><'m-wrap span5 customTablePagingStyle'l>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sEmptyTable": "There are no records to display based on your filters.",
"sLengthMenu": "_MENU_ records per page",
"oPaginate": {
"sPrevious": "Prev",
"sNext": "Next"
}
},
});
我有这段代码可以在我的项目中的每个 $("table.tablesorter") 上应用 DataTable。
现在我的客户想要打开排序。另外,他希望显示新行,而很少显示。
转bSort: true 后有什么办法可以将类添加到仅对该列关闭排序的列?
编辑: 您可以通过在您的 , 上使用 no-sort 类来禁用,
并使用此初始化代码:
// Disable sorting on the no-sort class
"aoColumnDefs" : [ {
"bSortable" : false,
"aTargets" : [ "no-sort" ]
} ]
我现在有一个新问题。
当我应用排序时,已排序 <th> 的 css 背景丢失,而未排序的背景保持不变。
我想保留排序列的格式。
添加以下选项不起作用。
bSortClasses: false,
编辑 2:
我发现了
table.table thead .sorting {
background: url('images/sort_both.png') no-repeat center right;
}
正在覆盖我在此处定义的背景颜色。
table-advance thead tr th {
background-color: #DDD;
font-size: 14px;
font-weight: bold;
color: #666;
}
【问题讨论】:
-
它不是上述问题的重复...
-
您是否尝试为库添加的类添加 CSS 样式规则?没有看到页面示例就很难理解真正的问题。你能创建一个jsfiddle吗?
-
不,我有很多脚本无法创建 jsfiddle。
-
所以基本上你回答了你自己的问题(并提供了你的解决方案,干得好!),对吧?关于您最近的 CSS 问题:
table-advance应该以点开头并且比覆盖规则更具体,即使用.table-advance thead .sorting并添加background-image: none;以删除通过数据表排序类应用的背景图像。
标签: javascript jquery jquery-datatables