BootStrap 风格 Table自定义排序

 

 

 

一段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>

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值