jQuery implements Table paging effect

jQuery implements Table paging effect

This article shares the specific code of jQuery to achieve the Table paging effect for your reference. The specific content is as follows

CSS:

<style>
    .pager {
        font-size: 18px;
    }
 
    .pagerTotal {
        font-size: 18px;
        height: 36px;
        line-height: 36px;
        margin-left: 2px;
    }
 
    .pager_a {
        display: block;
        width: 36px;
        height: 36px;
        line-height: 36px;
        float: left;
        text-align: center;
        border: 1px solid black;
        color: black;
        margin-left: 2px;
        cursor: pointer;
    }
 
    .pager_a_red {
        display: block;
        width: 36px;
        height: 36px;
        line-height: 36px;
        float: left;
        text-align: center;
        border: 1px solid red;
        color: red;
        font-weight: bold;
        margin-left: 2px;
        cursor: pointer;
    }
</style>

HTML:

<span class="pager"></span>&nbsp;<span class="pagerTotal"></span>
<table>
<tr>
    <th>Brand</th>
    <th>Shop</th>
    <th>Warehouse</th>
</tr>
<tbody id='tbody'></tbody>
</table>
<span class="pager"></span>&nbsp;<span class="pagerTotal"></span>

JavaScript:

<script>
    // Initialize $(function () {
        ReportPage(1);
    });
    //Load report - paging function ReportPage(pageIndex) {
        var index = pageIndex; //page number var size = 500; //number of entries per page var startDate = $("#startDate").val();
 
        $("tbody").empty();
        $.ajax({
            async: false,
            type: "GET",
            data: {
                "startDate": startDate,
                "pageIndex": index,
                "pageSize": size,
            },
            url: "/Controller/GetData",
            dataType: "json",
            success: function (request) {
                //Spelling table$.each(request.data, function (i, field) {
                    var html = "";               
                    html += "<tr>";
                    html += "<td>" + field.brand+ "</td>";        
                    html += "<td>" + field.Shop+ "</td>";
                    html += "<td>" + field.warehouse+ "</td>";
                    html += "</tr>";
                    $("#tbody").append(html);
                });           
                Pages(pageIndex, request.allPage, request.total);//Generate paging},
        });
    }
 
    //Paging button function Pages(pageIndex, pageCount, pageTotal) {
        $(".pagerTotal").html("&nbsp;&nbsp;Total: <font color='red'>" + pageTotal + "</font>&nbsp;Data!");
        $(".pager").empty();
        var page = "";
        for (var i = 0; i < pageCount; i++) {
            if ((i + 1) == pageIndex) {
                page += "<span class='pager_a_red'>" + (i + 1) + "</span>";
            }
            else {
                page += "<span class='pager_a' onclick='ReportPage(" + (i + 1) + ")'>" + (i + 1) + "</span>";
            }
        }
        $(".pager").append(page);
    }
</script>

MVC:

public ActionResult GetData(string startDate, int pageIndex, int pageSize)
        {
                string json = string.Empty;          
                if (!string.IsNullOrEmpty(startDate))
                {
                    int total = 0;
                    int allPage = 0;
                    DataTable dt = bll.GetData(startDate, pageIndex, pageSize, out total, out allPage);
                    if (dt != null && dt.Rows.Count > 1)
                    {
                        json = JsonConvert.SerializeObject(new
                        {
                            total = total, //Total number of records allPage = allPage, //Total number of pages data = dt, //Data after paging });
                    }
                }        
                return Content(json);
        }

Get the paging data dataTable, total data count total, and total page count allpage:

public DataTable GetDate(string startDate, int pageIndex, int pageSize, out int total, out int allPage)
{
    //Calculate the total number of data and total number of pages string sqlCount = "select count(*) from table where date='"+startDate+"'"; //Get the total number of data total = int.Parse(SqlHelper.GetSingel(sqlCount ).ToString()); //Total number of data rows allPage = total / pageSize; //Total number of pages = total number of data rows / number of rows per page allPage += total % pageSize == 0 ? 0 : 1; //Less than one page is also counted as one page //Get paging data string sql = "";
    sql = "DECLARE @PageIndex INT;";
    sql = "DECLARE @PageSize INT;";
    sql = "SET @PageIndex=" + pageIndex;
    sql = "SET @PageSize=" + pageSize;
 
    sql += " SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID desc) rownum, * FROM table where date ='"+ startDate +"')a";
    sql += " WHERE rownum > @PageSize * (@PageIndex - 1) AND rownum <= @PageSize * @PageIndex";
    sql += "order by ID desc";
 
    DataTable dt = SqlHelper.GetDate(sql);//paging data return dt;
}

Preview:

Clicking the page number will re-call ajax to get new data.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Experience in developing jQuery plugin DataTables paging
  • Using jQuery DataTables to implement data paging display function in Asp.net MVC
  • jQuery DataTable implements dynamic paging in front and back
  • jQuery dataTable background loading data and paging example code
  • jQuery DataTable Server-Side Paging
  • ASP.NET MVC+EF Notes on using jqGrid and jquery Datatables for server-side paging
  • jQuery DataTables plugin custom Ajax paging example analysis
  • A preliminary study on the efficiency of Table paging code in JQuery to build a client/service separation link model

<<:  Markup language - simplified tags

>>:  Detailed explanation of the process of Zabbix active, passive and web monitoring in distributed monitoring system

Recommend

Implementation of vue-nuxt login authentication

Table of contents introduce Link start Continue t...

JS achieves five-star praise effect

Use JS to implement object-oriented methods to ac...

How to set up virtual directories and configure virtual paths in Tomcat 7.0

Tomcat7.0 sets virtual directory (1) Currently, o...

Solutions to black screen when installing Ubuntu (3 types)

My computer graphics card is Nvidia graphics card...

Implementation steps for installing Redis container in Docker

Table of contents Install Redis on Docker 1. Find...

Install and configure ssh in CentOS7

1. Install openssh-server yum install -y openssl ...

Nginx uses reverse proxy to implement load balancing process analysis

Introduction Based on docker container and docker...

Detailed tutorial of using stimulsoft.reports.js with vue-cli

vue-cli uses stimulsoft.reports.js (nanny-level t...

How to configure Hexo and GitHub to bind a custom domain name under Windows 10

Hexo binds a custom domain name to GitHub under W...

Tomcat CentOS installation process diagram

Tomcat CentOS Installation This installation tuto...

Docker batch start and close all containers

In Docker Start all container commands docker sta...

Solution to MySQL remote connection failure

I have encountered the problem that MySQL can con...