html - HTML & CSS:排序表按钮不起作用
问题描述
我正在使用 datatable.js,并且正在尝试使我的表格可排序。排序工作,但我不知道为什么我的图标没有出现。
我的代码:
table.users thead .sorting:before, table.users thead .sorting_asc:before, table.users thead .sorting_asc_disabled:before, table.users thead .sorting_desc:before, table.users thead .sorting_desc_disabled:before {
top: 2px;
right: 1em;
content: "\2191";
}
div.dataTables_wrapper div.dataTables_filter {
text-align: right;
}
table.users thead .sorting:after, table.users thead .sorting:before, table.users thead .sorting_asc:after, table.users thead .sorting_asc:before, table.users thead .sorting_asc_disabled:after, table.users thead .sorting_asc_disabled:before, table.users thead .sorting_desc:after, table.users thead .sorting_desc:before, table.users thead .sorting_desc_disabled:after, table.users thead .sorting_desc_disabled:before {
position: absolute;
bottom: .9em;
display: block;
opacity: .3;
}
<table id="users" class="table table-hover users" width="100%">
<thead>
<tr>
<th class="sorting">Nickname</th>
<th>Rank</th>
<th>SteamID</th>
<th>Date</th>
<th>Last Access</th>
<th class="disabled-sorting text-right">Actions</th>
</tr>
</thead>
解决方案
以下内容很容易实现,但与您的要求有一些不同。
桌子:
款式:
/* hide the default sort order triangles */
table.dataTable thead .sorting,
table.dataTable thead .sorting_asc,
table.dataTable thead .sorting_desc {
background-image: none;
}
/* not sorted */
table.dataTable thead .sorting:after {
padding-left: 1em;
content: "\2191\2193";
opacity: .3;
}
/* sorted ascending */
table.dataTable thead .sorting_asc:after {
padding-left: 1em;
content: "\2191";
}
/* sorted descending */
table.dataTable thead .sorting_desc:after {
padding-left: 1em;
content: "\2193";
}
注意事项:
1) 这使用 DataTables 提供的类名 - 没有使用自定义类。
2) 箭头在每个标题单元格内没有右调整。相反,它们稍微位于标签的右侧。如果您的列标题没有清晰的边界,那么这实际上可能是一件好事。
3) 对于排好序的列,只显示一个箭头。您的屏幕截图需要两个箭头(一个不透明度较低)。
如果这不能满足您的需求,它至少可以为您指明您想要去的方向。
推荐阅读
- c - c中的警告称为“'s1'和's2'在此函数中未初始化”
- r - 如何在 R 中打开 .json.gz 格式的文件?
- swift - 单击地图注释时的 SwiftUI 操作
- linux - 签入文件数据与语法匹配
- sql - Redshift - 按类别查找贡献百分比
- javascript - 如何使用nodejs从云firestore中的单个查询中获取响应对象?
- vector - Bukkit/Spigot - 命中检测的弹丸位置完全错误
- javascript - JS再次调用时如何在true时停止前一个
- python - 在特定列中查找唯一行
- angular - 在 Redux/ngrx 中转换存储属性的位置