element-ui表格排序

html

 <el-table
      ref="singleTable"
      :data="tableData"
      highlight-current-row
      style="width: 100%"
      size="medium"
      border
      @cell-click="transferId"
      ~~:default-sort="{prop: 'id_purchase', order: 'descending'}"~~  
    >
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column property="id" label="产品" width="120"></el-table-column>
      <el-table-column property="id_pageview" label="pageview" width="120" sortable></el-table-column>
      <el-table-column property="id_checkout" label="checkout" width="120" sortable></el-table-column>
      <el-table-column
        property="id_purchase"
        label="purchase"
        width="120"
        sortable
        ~~:sort-method="sortByPurchase"~~ 
      ></el-table-column>
      <el-table-column property="belong" label="belong" width="120"></el-table-column>
      <el-table-column property="pimg" label="pimg" width="240">
        <template slot-scope="scope">
          <img :src="scope.row.pimg" alt style="width:50px;height:50px;" />
        </template>
      </el-table-column>
      <el-table-column property="url" label="url" width="240">
        <template slot-scope="scope">
          <a
            :href="scope.row.url"
            style="text-decoration:none;font-size:14px;"
            target="_blank"
          >{{scope.row.url}}</a>
        </template>
      </el-table-column>
      <el-table-column property="nums" label="访问IP"></el-table-column>
    </el-table>

可以通过 Table 的default-sort属性设置默认的排序列和排序顺序。在上面的代码已用~~~标示出。
如果想让哪列进行排序直接加sortable即可。
如果要设置默认排序,需要设置sort-method,设置sort-method的前提是sortable=“true”方法跟Array.sort(function(a,b))基本一样.js代码如下:

methods: {
    sortByPurchase(obj1, obj2) {
      var a = obj1.id_purchase;
      var b = obj2.id_purchase;
      return a - b;
     }
    }
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值