如何在 jQuery 表排序器中的个人解析器上设置初始排序顺序?
我在 jQuery Tablesorter 插件 中制作了一个自定义解析器。我希望在加载页面时使用自定义解析器将表按 3 列排序。
我已经尝试过:
<script type="text/javascript">
$(document).ready(function () {
$("#statusTable").tablesorter({ sortList: [[3, 0], [4, 0], [5, 0]]}, { headers: { 3: { sorter: 'status' }, 4: { sorter: 'status' },
5: { sorter: 'status' }, 0: { sorter: false }, 7: { sorter: false} }});
});
</script>
加载页面时对列进行排序,但它们是按字母顺序排序的。
我尝试过的另一个脚本:
<script type="text/javascript">
$(document).ready(function () {
$("#statusTable").tablesorter({ headers: { 1: { sorter: 'status' }, 2: { sorter: 'status' },
3:{ sorter: 'status'}, 5:{ sorter: false}}}, { sortList: [[1,0],[2,0],[3,0]] }); });
</script>
但是列根本没有排序。
最后一个脚本:
<script type="text/javascript">
$(document).ready(function () {
$("#statusTable").tablesorter({ sortList: [[3, 0], [4, 0], [5, 0]], headers: { 3: { sorter: 'status' }, 4: { sorter: 'status' },
5: { sorter: 'status' }}, { headers: { 3: { sorter: 'status' }, 4: { sorter: 'status' },
5: { sorter: 'status' }, 0: { sorter: false }, 7: { sorter: false} }});
});
</script>
但是表格排序器不再工作了。
有人有什么建议吗?
I have made a custom parser in jQuery Tablesorter plugin. I want to have the table to be sorted on 3 columns with that custom parser when you load the page.
I have tried this:
<script type="text/javascript">
$(document).ready(function () {
$("#statusTable").tablesorter({ sortList: [[3, 0], [4, 0], [5, 0]]}, { headers: { 3: { sorter: 'status' }, 4: { sorter: 'status' },
5: { sorter: 'status' }, 0: { sorter: false }, 7: { sorter: false} }});
});
</script>
The columns are sorted when the page is loaded but they are sorted alphabetically.
Another script I tried:
<script type="text/javascript">
$(document).ready(function () {
$("#statusTable").tablesorter({ headers: { 1: { sorter: 'status' }, 2: { sorter: 'status' },
3:{ sorter: 'status'}, 5:{ sorter: false}}}, { sortList: [[1,0],[2,0],[3,0]] }); });
</script>
But then the columns aren't sorted at all.
Last script:
<script type="text/javascript">
$(document).ready(function () {
$("#statusTable").tablesorter({ sortList: [[3, 0], [4, 0], [5, 0]], headers: { 3: { sorter: 'status' }, 4: { sorter: 'status' },
5: { sorter: 'status' }}, { headers: { 3: { sorter: 'status' }, 4: { sorter: 'status' },
5: { sorter: 'status' }, 0: { sorter: false }, 7: { sorter: false} }});
});
</script>
But then the tablesorter didn't work anymore.
Does anyone have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您对 JSON 有点满意。您是否尝试过清理代码,也许使用缩进来查看语法的位置?
这是您清理后的第一个版本:
我假设您的第一个版本是最好的(与您在测试中的第一直觉相同的前提)。您不必要地将
headers
包裹在大括号中(事实上,从未关闭它)。I think you're a little brace-happy on your JSON. Have you tried just cleaning up your code, and maybe using indenting to see where you're at with syntax?
Here's your first version cleaned up:
I'm going on the assumption that your first was best (along the same premise as going with your first instinct on a test). You were wrapping
headers
in braces unnecessarily (and, in-fact, never closed it).