How to use pagination on HTML tables?

前端 未结 8 621
长发绾君心
长发绾君心 2020-12-07 21:41

I am trying to use this Pagination library in my HTML table page (specifically light theme) but somehow I am not able to understand how to plugin this library in such a way

8条回答
  •  孤街浪徒
    2020-12-07 22:09

    you can use this function . Its taken from https://convertintowordpress.com/simple-jquery-table-pagination-code/

    function pagination(){
        var req_num_row=10;
        var $tr=jQuery('tbody tr');
        var total_num_row=$tr.length;
        var num_pages=0;
        if(total_num_row % req_num_row ==0){
            num_pages=total_num_row / req_num_row;
        }
        if(total_num_row % req_num_row >=1){
            num_pages=total_num_row / req_num_row;
            num_pages++;
            num_pages=Math.floor(num_pages++);
        }
        for(var i=1; i<=num_pages; i++){
            jQuery('#pagination').append(""+i+"");
        }
        $tr.each(function(i){
            jQuery(this).hide();
            if(i+1 <= req_num_row){
                $tr.eq(i).show();
            }
    
        });
        jQuery('#pagination a').click(function(e){
            e.preventDefault();
            $tr.hide();
            var page=jQuery(this).text();
            var temp=page-1;
            var start=temp*req_num_row;
            //alert(start);
    
            for(var i=0; i< req_num_row; i++){
    
                $tr.eq(start+i).show();
    
            }
        });
    }
    

提交回复
热议问题