最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - tablesorter pager plugin - show all entries as default - Stack Overflow

matteradmin6PV0评论

I'm using this tablesorter version: /

Having this relevant html:

 <select class="pagesize form-control text-center">
        <option value="20">20</option>
        <option value="30">30</option>
        <option value="40">40</option>
        <option value="all" selected="selected">alle</option>
 </select>

and this js:

function tableSorter()
{  
  $("#tableOverview")
    .tablesorter()
    .tablesorterPager({container: $("#pager")});

  var rows = $('table.tablesorter')[0].config.totalRows;
  $('select.pagesize').find('option:contains("all")').val(rows);
}

Now I want to get displayed all items of the table as default / on loading. If it is not default and you have to choose it after loading the page, it works fine with this:

var rows = $('table.tablesorter')[0].config.totalRows;
$('select.pagesize').find('option:contains("all")').val(rows);

Setting the size in the defaults in jquery.tablesorter.pager.js to a high value works too, but it causes an error if you want to sort the table (nothing is shown then).

So is there any way to set the default size of the paging to all entries of the table?

I'm using this tablesorter version: http://tablesorter./docs/

Having this relevant html:

 <select class="pagesize form-control text-center">
        <option value="20">20</option>
        <option value="30">30</option>
        <option value="40">40</option>
        <option value="all" selected="selected">alle</option>
 </select>

and this js:

function tableSorter()
{  
  $("#tableOverview")
    .tablesorter()
    .tablesorterPager({container: $("#pager")});

  var rows = $('table.tablesorter')[0].config.totalRows;
  $('select.pagesize').find('option:contains("all")').val(rows);
}

Now I want to get displayed all items of the table as default / on loading. If it is not default and you have to choose it after loading the page, it works fine with this:

var rows = $('table.tablesorter')[0].config.totalRows;
$('select.pagesize').find('option:contains("all")').val(rows);

Setting the size in the defaults in jquery.tablesorter.pager.js to a high value works too, but it causes an error if you want to sort the table (nothing is shown then).

So is there any way to set the default size of the paging to all entries of the table?

Share Improve this question asked Oct 7, 2013 at 13:57 kinskekinske 6071 gold badge10 silver badges24 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

All you need to do different is to set the value to some really big number like 9999 in both the selected option value and in the pager size option (demo):

HTML

<select class="pagesize">
    <option value="10">10</option>
    <option value="20">20</option>
    <option value="30">30</option>
    <option value="40">40</option>
    <option selected="selected" value="9999">all</option>
</select>

Javascript

$('table')
    .tablesorter({
        widthFixed: true,
        widgets: ['zebra']
    })
    .tablesorterPager({
        container: $("#pager"),
        size: 9999 // pick a number larger than your table
    });
   // edit in jquery.tablesorter.pager.js,
   // add to construct function
   var total_page= config.totalPages;
   var total_rows_per_page = config.size;
   var total_rows = total_page*total_rows_per_page;

   // set value all to .pagesize
   $(".pagesize").append('<option value="' + total_rows  + '">All</option>');
Post a comment

comment list (0)

  1. No comments so far