开发者

How to set an initial sort order on a personal parser in jQuery tablesorter?

开发者 https://www.devze.com 2023-01-29 05:09 出处:网络
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 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消