dataTables如何添加排序图像/图标
dataTables how to add sorting image/icon?
我使用dataTablesjquery。我想将排序图像添加到列中,图像shd也会在排序时发生变化。也就是说,如果图像显示降序图标,单击时应该会变为升序图标。如何使用dataTablesjquery完成?
我的代码:
$("#rates").dataTable({
"bPaginate": false,
"sScrollY": "250px",
"bAutoWidth": false,
"bScrollCollapse": true,
"fnInitComplete": function() {
this.css("visibility", "visible");},
"bLengthChange": false
});
$(document).ready(function() {
$("#tblVal").dataTable({
"bPaginate": false,
"sScrollY": "250px",
"bAutoWidth": false,
"bScrollCollapse": true,
"fnInitComplete": function() {
this.css("visibility", "visible");
},
"bLengthChange": false
});
});
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>new document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css" rel="stylesheet" />
</head>
<body>
<div id="foo">
<table id="tblVal" class="data display datatable">
<thead>
<tr>
<th>s.no</th>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>100</td>
<td>vsa</td>
</tr>
<tr>
<td>2</td>
<td>101</td>
<td>asa</td>
</tr>
<tr>
<td>3</td>
<td>102</td>
<td>nfsa</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
确保你已经添加了一个合适的js和css文件。试试这个代码,它对我有效
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<script type="text/javascript">
$(document).ready(function(){
$("#tblVal").dataTable({
"bPaginate": false,
"sScrollY": "250px",
"bAutoWidth": false,
"bScrollCollapse": true,
"fnInitComplete": function() {
this.css("visibility", "visible");},
"bLengthChange": false
});
});
</script>
</head>
<body>
<div id="foo">
<table id="tblVal" class="data display datatable">
<thead>
<tr>
<th>s.no</th>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>100</td>
<td>vsa</td>
</tr>
<tr>
<td>2</td>
<td>101</td>
<td>asa</td>
</tr>
<tr>
<td>3</td>
<td>102</td>
<td>nfsa</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
在项目中包含图像文件夹后,调整CSS中的链接以指向图像。在CSS中查找以下代码:
table.dataTable thead .sorting {
background-image: url("../images/sort_both.png");
}
默认情况下,datatable启用排序。您无法更改数据表中排序图标的颜色,因为这些图标不是图标,而是PNG图像。您需要覆盖那些CSS属性(数据表1.10)
- 升序
table.dataTable thead .sorting_asc {
background-image: url("/YourImageFolder/sort_asc.png")
}
- 降序
table.dataTable thead .sorting_desc {
background-image: url("/YourImageFolder/sort_desc.png")
}
- 两者均已禁用
table.dataTable thead .sorting {
background-image: url("/YourImageFolder/sort_both.png")
}
- 已禁用升序
table.dataTable thead .sorting_asc_disabled {
background-image: url("/YourImageFolder/sort_asc_disabled.png")
}
- 已禁用降序
table.dataTable thead .sorting_desc_disabled {
background-image: url("/YourImageFolder/sort_desc_disabled.png")
}
相关文章:
- Javascript排序的图像弹出窗口..可以't单独弹出
- 我该如何使网页上的图像网格可排序
- 抽搐流图像并仅在在线流上排序
- Jquery 表排序不适用于图像
- 如何按维度对图像进行排序
- 具有排序问题的流体动态图像布局
- 使用Stupid表插件对图像进行排序
- 使用radio和jQuery对图像进行排序
- 如何在metro.js中实现图像重新排序
- 如何使jQuery中的图像可排序元素可拖动
- 在上传图像之前,对它们进行排序
- 气泡根据图像的名称对其进行排序
- dataTables如何添加排序图像/图标
- 使用数据库与文件系统进行图像排序
- Dropzone图像重新排序
- 重新排序ul li与图像
- n -repeat track by $index打破图像字段排序
- Dojo DataGrid:不对列中的图像进行排序
- 动态图像排序和裁剪类似于google+相册视图
- 使用Jssor滑块对图像进行排序并显示结果