Show N rows per page in HTML table

前端 未结 3 1242
情书的邮戳
情书的邮戳 2021-01-24 17:08

Hello I have an html table with a lot of rows and I use a JavaScript code to add a pagination option, works fine but when I load the document shows all the rows and I want to sh

3条回答
  •  故里飘歌
    2021-01-24 17:41

    First, I would suggest to use a library for table features like sorting, filtering, paging... as you are really re-inventing the wheel.

    But, for the problem you raise, you have to make two adjustments:

    1. In your HTML, mark the option with selected that has your desired number of pages to display at page load, like 3:

      
      
    2. In your code, call the .trigger('change') method on the maxRows element:

      $('#maxRows').on('change', function() {
          // all code here can stay as it is
          // ...
      }).trigger('change');
      

    That's it.

    See updated fiddle

提交回复
热议问题