I have made a custom parser in jQuery Tablesorter plugin. I want to have the table to be sorted on 3 columns wi开发者_StackOverflow社区th 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?
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:
<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>
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).
精彩评论