一段Html,排序的表头设置样式
<table id="contentTable" class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>序号</th>
<th id="packCntTh" class="sortCls" data-type="packCnt">排序字段(包裹数量) <i></i></th>
</tr>
</thead>
<tbody><td></td><td></td></tbody>
</table>
设置鼠标移上显示小手形状
<style type="text/css">
.sortCls{
cursor:pointer;
}
</style>
当鼠标点击某一列进行排序,默认是降序,再次点击是升序,再点击是降序,添加向上或向下的箭头
<script type="text/javascript">
$(document).ready(function(){
$(".sortCls").click(function(){
var sortColumn = $(this).data('type');
var sortType;
if($(this).find("i").hasClass("icon-arrow-down")){
sortType = "asc";
$("i").attr("class", "");
$(this).find("i").addClass("icon-arrow-up");
}else if($(this).find("i").hasClass("icon-arrow-up")){
sortType = "desc";
$("i").attr("class", "");
$(this).find("i").addClass("icon-arrow-down");
}else{
$("i").attr("class", "");
$(this).find("i").addClass("icon-arrow-down");
sortType = "desc";
}
//table 设置两个隐藏域,用于向后台传递排序字段和排序方式(降序/升序)
$("#sortType").attr("value",sortType);
$("#sortColumn").attr("value",sortColumn);
//提交Table所在的Form表单,发起请求
$("#searchForm").attr("action","${ctx}/doSearchUrl");
$("#searchForm").submit();
loading('正在查询,请稍等...');
});
});
</script>