CSS 自定义前端排序插件

因项目有个需求需要对table的当前页进行排序,当前页面有临时数据,所以只能在前端把这些数据排序再更新表格,没有符合需求的控件可以用,就用CSS整了一个,适合一些用在table要求比较灵活的排序需求上。

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <script src="http://192.168.83.178:7006/Scripts/jquery-3.3.1.js"></script>

  <title>Title</title>

  <style type="text/css">
    .on {
      width: 100px;
      height: 40px;
      line-height: 40px;
      display: table-cell;
      position: relative;
    }

    .on a {
      display: block;
      overflow: hidden;
      width: 100%;
      height: 30px;
      line-height: 30px;
      text-align: center;
      color: #5e5e5e;
    }

    .arrow_bottom {
      content: '';
      width: 0;
      height: 0;
      display: block;
      border-style: solid;
      border-width: 0 6px 6px;
      border-color: transparent transparent #5e5e5e;
      position: absolute;
      transform: rotate(180deg);
      bottom: 11px;
      right: 20px;
    }
	 .arrow_bottom_select {
      content: '';
      width: 0;
      height: 0;
      display: block;
      border-style: solid;
      border-width: 0 6px 6px;
      border-color: transparent transparent #7a80dd;
      position: absolute;
      transform: rotate(180deg);
      bottom: 11px;
      right: 20px;
    }

    .arrow_up {
      content: '';
      width: 0;
      height: 0;
      display: block;
      border-style: solid;
      border-width: 0 6px 6px;
      border-color: transparent transparent #5e5e5e;
      position: absolute;
      top: 11px;
      right: 20px;
    }

    .arrow_up_select {
      content: '';
      width: 0;
      height: 0;
      display: block;
      border-style: solid;
      border-width: 0 6px 6px;
      border-color: transparent transparent #7a80dd;
      position: absolute;
      top: 11px;
      right: 20px;
    }
  </style>
</head>
<body>

<div class="on" onclick="customSort()">Match%<i id="arrow_up" class="arrow_up"></i><i id="arrow_bottom" class="arrow_bottom"></i></div>
</body>
<script>
  var status = 'default';
   function customSort(){

     if(status === 'default'){
      status = 'asc';
      $("#arrow_up").removeClass('arrow_up');
      $("#arrow_up").addClass('arrow_up_select')
      console.log('default');
     }else if(status==='asc'){
      status = 'desc';
      console.log('asc');
      $("#arrow_up").removeClass('arrow_up_select');
      $("#arrow_up").addClass('arrow_up')
      $("#arrow_bottom").removeClass('arrow_bottom');
      $("#arrow_bottom").addClass('arrow_bottom_select')
     }else if(status==='desc'){
      status = 'default';
      console.log('desc');
      $("#arrow_bottom").removeClass('arrow_bottom_select');
      $("#arrow_bottom").addClass('arrow_bottom')
     }
     alert('click')
   }
</script>
</html>

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值