我的列表的列是循环的出来的 前面可以排序的都吗没有问题 就只有其中一个排序出现列表显示的顺序与后端返回的数据的顺序不一致
<el-table :data="dataList"
ref="multipleTable"
@sort-change="sortChange">
<template v-for="(item,index) in colList.dispfields">
<el-table-column
:sortable="item.isorder==='yes'"
>
</el-table-column>
</template>
</el-table>
之前的写法是这个样子的 很多循环出来的都是正常的 只有其中一个显示的顺序是错误的
不知道为什么 查了文档说:
如果需要后端排序,需将sortable
设置为custom
,同时在 Table 上监听sort-change
事件,在事件回调中可以获取当前排序的字段名和排序顺序,从而向接口请求排序后的表格数据
然后代码改成这样就好了
<el-table :data="dataList"
ref="multipleTable"
@sort-change="sortChange">
<template v-for="(item,index) in colList.dispfields">
<el-table-column
:sortable="item.isorder==='yes'?'custom':false"
>
</el-table-column>
</template>
</el-table>
远程请求的时候 sortable 需要设置成 custom
虽然不知道为啥但是文档就是这样写的 哈哈哈哈哈 那就先这样吧