Search code examples
jquerytablesorter

Table sorter initial page size doesn't work


I'm trying to set the initial page size using the pager functionality but it doesn't work. Here is what I have for the javascript and HTML.

<link rel="stylesheet" href="/static/javascript/themes/blue/style.css" type="text/css" media="print, projection, screen" />
<script type="text/javascript" src="/static/javascript/jquery-1.11.2.min.js"></script> 
<script type="text/javascript" src="/static/javascript/jquery.tablesorter.js"></script>
<script type="text/javascript" src="/static/javascript/jquery.tablesorter.pager.js"></script>
<script type="text/javascript">
    $(function() {
        $("table")
            .tablesorter({widthFixed: true, widgets: ['zebra']})
            .tablesorterPager({container: $("#pager"), size: 10});

    });
    </script>


</head>

And here is the table:

    <table id="companies" class="tablesorter"> 
    <thead> 
      <tr>
        <th>Name</th> 
        ...

      </tr>
      </thead>
    <tbody>
</table>

<div id="pager" class="pager">
    <form>
        <img src="images/first.png" class="first"/>
        <img src="images/prev.png" class="prev"/>
        <input type="text" class="pagedisplay"/>
        <img src="images/next.png" class="next"/>
        <img src="images/last.png" class="last"/>
        <select class="pagesize">
            <option value="2">2 per page</option>
            <option value="5">5 per page</option>
            <option value="10">10 per page</option>

        </select>
    </form>
</div>

The table works and sorts, but what I cannot seem to control is the level of pagination. I know I don't have the controls listed (to save space) but I cannot get the initial page size working.


Solution

  • It appears that you are using the original version of tablesorter (v2.0.5, from tablesorter.com) along with jQuery v1.11.2.

    The problem is that the jQuery $.browser function was completely removed in jQuery v1.9+, so that code won't work because there is a javascript error preventing the pager plugin from initializing completely.

    To fix this either:

    1. Switch to jQuery < 1.9.
    2. Try out my fork of tablesorter which includes lots of fixes & enhancements.
    3. If you choose to stick with the original tablesorter, there is a GitHub repository, and an open issue which you can follow for updates.