Create Pagination Table in jQuery, CSS, Bootstrap

Pagination is very important part to display lot’s of content in single page. If you want to display large pagination table data you must go with dynamic pagination using php. But if you have some table data where you want to apply pagination then you can simply create jquery method to show hide data act like pagination which help your website user navigate easily. So in this tutorial I am going share simple jquery, css, bootstrap based pagination which you can apply on your website html table and make it Pagination Table .

 Pagination Table


You have to include some dependent libraries which help us to create and design Pagination Table.

<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>


Create simple html table with some sample data where we have to apply jquery function and make it Pagination Table.

    <div class="container">
        <h2>Select Number Of Rows</h2>
                <div class="form-group">    <!--        Show Numbers Of Rows        -->
                    <select class  ="form-control" name="state" id="maxRows">
                         <option value="5000">Show ALL Rows</option>
                         <option value="5">5</option>
                         <option value="10">10</option>
                         <option value="15">15</option>
                         <option value="20">20</option>
                         <option value="50">50</option>
                         <option value="70">70</option>
                         <option value="100">100</option>
<table class="table table-striped table-class" id= "table-id">
        <td>Rajah Armstrong</td>
        <td>Oct 26, 2015</td>
        <td>Kuame Parsons</td>
        <td>Aug 2, 2015</td>
        <td>Ira Parker</td>
        <td>Sep 15, 2015</td>
        <td>Dante Carlson</td>
        <td>Nov 28, 2015</td>
        <td>Nathan Bernard</td>
        <td>Aug 4, 2016</td>
        <td>Dillon Poole</td>
        <td>Apr 25, 2016</td>
        <td>Hu Leach</td>
        <td>Nov 3, 2015</td>
        <td>Dean Lucas</td>
        <td>Mar 10, 2016</td>
        <td>Dorian Durham</td>
        <td>Nov 11, 2016</td>
<!--        Start Pagination -->
            <div class='pagination-container' >
                  <ul class="pagination">
            <li data-page="prev" >
                                     <span> < <span class="sr-only">(current)</span></span>
                   <!-- Here the JS Function Will Add the Rows -->
        <li data-page="next" id="prev">
                                       <span> > <span class="sr-only">(current)</span></span>


Styling your page and Pagination page count.

    background-color: #eee; 
table th , table td{
    text-align: center;
table tr:nth-child(even){
    background-color: #BEF2F5
.pagination li:hover{
    cursor: pointer;


Copy the below jquery code script and paste it on page. replace the classes and id’s with your table or make it same.

    function getPagination (table){
                var lastPage = 1 ; 
        lastPage = 1 ; 
         $('.pagination').find("li").slice(1, -1).remove();
            var trnum = 0 ;                                 
            var maxRows = parseInt($(this).val());          
            if(maxRows == 5000 ){
            }else {
            var totalRows = $(table+' tbody tr').length;        
             $(table+' tr:gt(0)').each(function(){          
                if (trnum > maxRows ){                      
                }if (trnum <= maxRows ){$(this).show();}
             if (totalRows > maxRows){                      
                var pagenum = Math.ceil(totalRows/maxRows); 
                for (var i = 1; i <= pagenum ;){            
                $('.pagination #prev').before('<li data-page="'+i+'">\
                                      <span>'+ i++ +'<span class="sr-only">(current)</span></span>\
            }                                               // end if row count > max rows
            $('.pagination [data-page="1"]').addClass('active'); 
            $('.pagination li').on('click',function(evt){       
                var pageNum = $(this).attr('data-page');    
                var maxRows = parseInt($('#maxRows').val());            
                if(pageNum == "prev" ){
                    if(lastPage == 1 ){return;}
                    pageNum  = --lastPage ; 
                if(pageNum == "next" ){
                    if(lastPage == ($('.pagination li').length -2) ){return;}
                    pageNum  = ++lastPage ; 
                lastPage = pageNum ;
                var trIndex = 0 ;                           
                $('.pagination li').removeClass('active');  
                $('.pagination [data-page="'+lastPage+'"]').addClass('active');
                // $(this).addClass('active');                  
                 $(table+' tr:gt(0)').each(function(){      
                    if (trIndex > (maxRows*pageNum) || trIndex <= ((maxRows*pageNum)-maxRows)){
                    }else {$(this).show();}                 
                    $('table tr:eq(0)').prepend('<th> ID </th>')
                    var id = 0;
                    $('table tr:gt(0)').each(function(){    

See live demo and download source code.


This awesome script developed by yasser-mas, Visit their official codepen repository for more information and follow for future updates.

Don’t forget to Subscribe My Public Notebook for more useful free scripts, tutorials and articles.