Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table: support sort-by #7828

Merged
merged 4 commits into from
Oct 31, 2017
Merged

Table: support sort-by #7828

merged 4 commits into from
Oct 31, 2017

Conversation

wangfengming
Copy link
Contributor

@wangfengming wangfengming commented Oct 30, 2017

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow Element's contributing guide (中文 | English).

  • Make sure you are merging your commits to dev branch.

  • Add some descriptions and refer relative issues for you PR.

  • Table 支持按 sort-by 排序,如对 status_title 列排序时,按照 status_code 排序:

<el-table-column prop="status_title" sort-by="status_code"></el-table-column>
  • 以前使用 Array.prototype.sort 没有考虑排序的稳定性,修复该问题
  • 以前的排序,会对同一个 item 多次调用 getValueByPath 方法,现在只会对每个 item 调用 getValueByPath 一次

@wangfengming
Copy link
Contributor Author

wangfengming commented Oct 30, 2017

使用 sort-by 会比使用 sort-method 方便快捷,如果没有 sort-by,会有两种实现方式

  • 使用 template
    <el-table-column prop="status_code">
        <template slot-scope="scope">{{scope.row.status_title}}</template>
    </el-table-column>
  • 使用 sort-method
    <el-table-column prop="status_title" sort-method=sortMethod></el-table-column>
    sortMethod(a, b) {
       return a.status_code - b.status_code
    }

但使用 sort-by 只需要这样:

<el-table-column prop="status_title" sort-by="status_code"></el-table-column>

@Leopoldthecoder
Copy link
Contributor

sort 相关的测试挂了,可以看一下

@wangfengming
Copy link
Contributor Author

wangfengming commented Oct 30, 2017

好奇怪,我本机跑测试,每次到radio那里就会停下来。感觉没安装好。
我犯了个低级错误 if (!Array.isArray) { -> if (!Array.isArray(sortBy)) {
我可以重新打开不?我本机跑不起来测试/(ㄒoㄒ)/~~

@wangfengming
Copy link
Contributor Author

测试失败
test fail on Radio

@Leopoldthecoder
Copy link
Contributor

可以继续提交,我打开了

@wangfengming
Copy link
Contributor Author

通了
pass

@Leopoldthecoder Leopoldthecoder merged commit 8777180 into ElemeFE:dev Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants