element table sortable排序的使用以及出现小数、%排序错乱

这篇博客介绍了如何在带有小数点的数据中实现正确的排序,以及在显示百分比时避免排序错误的方法。通过在`el-table-column`组件中添加`sortable`属性和自定义的`sort-method`,可以确保建设规模列按照数值正确排序。同时,对于价格列,通过在模板中处理数据并显示百分比,同时在`sort-method`中比较原始数值来保持排序的准确性。
摘要由CSDN通过智能技术生成

想实现以下结果:
带小数点排序问题
在这里插入图片描述
只需在表头上加上一个sortable属性即可
注意1、当数据中出现小数,导致排序错乱
解决方法:需要在el-table-column中添加:sort-method="(a,b)=>{return a.construction_scale - b.construction_scale}"

<el-table-column
	prop="construction_scale"
    label="建设规模"
    width="120"
    :sortable="true"
    :sort-method="(a, b) => { return a.construction_scale - b.construction_scale; }"
>
</el-table-column>

注意2、当数据需要使用%来显示,直接返回的数据含有%导致排序错乱,需要返回正常数字,在这里进行拼接%
解决方法: 拼接数字{{scope.row.price}}%

<el-table-column
    prop="price"
    label="价格"
    width="200"
    sortable
    :sort-method="(a,b)=>{return a.price - b.price}">
    <template slot-scope="scope">
      {{scope.row.price}}%
    </template>
</el-table-column>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值