1622571840

# Pandas MultiIndexing And Working With Time Series Data

### A Step By Step Example To Help Clean Time Series Data

Before we can do any predictive modeling or analytics, we first need to clean and format our data. The Pandas library has a lot of great tools to help speed this up — the faster we clean, the more time we can spend analyzing and modeling.

Here’s several weeks of stock price data for four stocks (for the sharp-eyed, yes I intentionally left a date out for Microsoft):

``````ticker       date    close
0    AAPL 2021-03-18   120.53
1    AAPL 2021-03-19   119.99
2    AAPL 2021-03-22   123.39
3    AAPL 2021-03-23   122.54
4    AAPL 2021-03-24   120.09
5    AAPL 2021-03-25   120.59
6    AAPL 2021-03-26   121.21
7    AMZN 2021-03-18  3027.99
8    AMZN 2021-03-19  3074.96
9    AMZN 2021-03-22  3110.87
10   AMZN 2021-03-23  3137.50
11   AMZN 2021-03-24  3087.07
12   AMZN 2021-03-25  3046.26
13   AMZN 2021-03-26  3052.03
14  GOOGL 2021-03-18  2021.34
15  GOOGL 2021-03-19  2026.96
16  GOOGL 2021-03-22  2030.69
17  GOOGL 2021-03-23  2041.33
18  GOOGL 2021-03-24  2032.53
19  GOOGL 2021-03-25  2032.46
20  GOOGL 2021-03-26  2024.73
21   MSFT 2021-03-18   230.72
22   MSFT 2021-03-19   230.35
23   MSFT 2021-03-22   235.99
24   MSFT 2021-03-23   237.58
25   MSFT 2021-03-24   235.46
26   MSFT 2021-03-25   232.34
``````

Let’s say we want to calculate the cumulative return for each stock over the week as well as compare their co-movement via a correlation matrix.

Currently the data is in stacked format where one stock is on top of the other. It’s much easier to analyze time series data such as stock prices in tabular format where each row is a date and each column is a stock.

#technology #business #machine-learning #programming #data-science

1620466520

## Your Data Architecture: Simple Best Practices for Your Data Strategy

If you accumulate data on which you base your decision-making as an organization, you should probably think about your data architecture and possible best practices.

If you accumulate data on which you base your decision-making as an organization, you most probably need to think about your data architecture and consider possible best practices. Gaining a competitive edge, remaining customer-centric to the greatest extent possible, and streamlining processes to get on-the-button outcomes can all be traced back to an organization’s capacity to build a future-ready data architecture.

In what follows, we offer a short overview of the overarching capabilities of data architecture. These include user-centricity, elasticity, robustness, and the capacity to ensure the seamless flow of data at all times. Added to these are automation enablement, plus security and data governance considerations. These points from our checklist for what we perceive to be an anticipatory analytics ecosystem.

#big data #data science #big data analytics #data analysis #data architecture #data transformation #data platform #data strategy #cloud data platform #data acquisition

1616818722

## Time Series Basics with Pandas

In my last post, I mentioned multiple selecting and filtering  in Pandas library. I will talk about time series basics with Pandas in this post. Time series data in different fields such as finance and economy is an important data structure. The measured or observed values over time are in a time series structure. Pandas is very useful for time series analysis. There are tools that we can easily analyze.

In this article, I will explain the following topics.

• What is the time series?
• What are time series data structures?
• How to create a time series?
• What are the important methods used in time series?

Before starting the topic, our Medium page includes posts on data science, artificial intelligence, machine learning, and deep learning. Please don’t forget to follow us on Medium 🌱 to see these posts and the latest posts.

Let’s get started.

#what-is-time-series #pandas #time-series-python #timeseries #time-series-data

1685205672

## Create Pagination Using jQuery

In this article, we will see how to create pagination using jquery. We will create jquery pagination using multiple ways. You can create pagination using different ways like creating pagination using simple HTML, you can create pagination in laravel using paginate() method. Also, create pagination laravel livewire, pagination using bootstrap.

We will create simple jquery pagination. Also, create pagination using jquery without a plugin and create jquery pagination with next and previous buttons

So, let's see dynamic pagination in jquery and bootstrap pagination in jquery

Example:

In this example, we will create pagination using jquery without using a plugin. Also, you can customize the pagination.

``````<!DOCTYPE html>
<html lang="en">
<head>
<title>How To Create Pagination Using jQuery - Websolutionstuff</title>
<style>
.current {
color: green;
}

#pagin li {
display: inline-block;
font-weight: 500;
}

.prev {
cursor: pointer;
}

.next {
cursor: pointer;
}

.last {
cursor:pointer;
margin-left:10px;
}

.first {
cursor:pointer;
margin-right:10px;
}

.line-content, #pagin, h3 {
text-align:center;
}

.line-content {
margin-top:20px;
}

#pagin {
margin-top:10px;
padding-left:0;
}

h3 {
margin:50px 0;
}
</style>
</head>
<body>
<h3>How To Create Pagination Using jQuery - Websolutionstuff</h3>
<div class="line-content">This is Page 1 content example with next and prev.</div>
<div class="line-content">This is Page 2 content example with next and prev.</div>
<div class="line-content">This is Page 3 content example with next and prev.</div>
<div class="line-content">This is Page 4 content example with next and prev.</div>
<div class="line-content">This is Page 5 content example with next and prev.</div>
<div class="line-content">This is Page 6 content example with next and prev.</div>
<div class="line-content">This is Page 7 content example with next and prev.</div>
<div class="line-content">This is Page 8 content example with next and prev.</div>
<div class="line-content">This is Page 9 content example with next and prev.</div>
<div class="line-content">This is Page 10 content example with next and prev.</div>
<div class="line-content">This is Page 11 content example with next and prev.</div>
<div class="line-content">This is Page 12 content example with next and prev.</div>
<div class="line-content">This is Page 13 content example with next and prev.</div>
<div class="line-content">This is Page 14 content example with next and prev.</div>
<div class="line-content">This is Page 15 content example with next and prev.</div>
<div class="line-content">This is Page 16 content example with next and prev.</div>
<div class="line-content">This is Page 17 content example with next and prev.</div>
<div class="line-content">This is Page 18 content example with next and prev.</div>
<div class="line-content">This is Page 19 content example with next and prev.</div>
<div class="line-content">This is Page 20 content example with next and prev.</div>
<div class="line-content">This is Page 21 content example with next and prev.</div>
<div class="line-content">This is Page 22 content example with next and prev.</div>
<div class="line-content">This is Page 23 content example with next and prev.</div>
<div class="line-content">This is Page 24 content example with next and prev.</div>
<div class="line-content">This is Page 25 content example with next and prev.</div>
<div class="line-content">This is Page 26 content example with next and prev.</div>
<div class="line-content">This is Page 27 content example with next and prev.</div>
<div class="line-content">This is Page 28 content example with next and prev.</div>
<div class="line-content">This is Page 29 content example with next and prev.</div>
<div class="line-content">This is Page 30 content example with next and prev.</div>
<div class="line-content">This is Page 31 content example with next and prev.</div>
<div class="line-content">This is Page 32 content example with next and prev.</div>
<div class="line-content">This is Page 33 content example with next and prev.</div>
<div class="line-content">This is Page 34 content example with next and prev.</div>
<div class="line-content">This is Page 35 content example with next and prev.</div>
<div class="line-content">This is Page 36 content example with next and prev.</div>
<div class="line-content">This is Page 37 content example with next and prev.</div>
<div class="line-content">This is Page 38 content example with next and prev.</div>
<div class="line-content">This is Page 39 content example with next and prev.</div>
<div class="line-content">This is Page 40 content example with next and prev.</div>
<div class="line-content">This is Page 41 content example with next and prev.</div>
<div class="line-content">This is Page 42 content example with next and prev.</div>
<div class="line-content">This is Page 43 content example with next and prev.</div>
<div class="line-content">This is Page 44 content example with next and prev.</div>
<div class="line-content">This is Page 45 content example with next and prev.</div>
<ul id="pagin"></ul>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script>

pageSize = 5;
incremSlide = 5;
startPage = 0;
numberPage = 0;

var pageCount =  \$(".line-content").length / pageSize;
var totalSlidepPage = Math.floor(pageCount / incremSlide);

for(var i = 0 ; i<pageCount;i++){
\$("#pagin").append('<li><a href="#">'+(i+1)+'</a></li> ');
if(i>pageSize){
\$("#pagin li").eq(i).hide();
}
}

var prev = \$("<li/>").addClass("prev").html("Prev").click(function(){
startPage-=5;
incremSlide-=5;
numberPage--;
slide();
});

prev.hide();

var next = \$("<li/>").addClass("next").html("Next").click(function(){
startPage+=5;
incremSlide+=5;
numberPage++;
slide();
});

\$("#pagin").prepend(prev).append(next);

\$("#pagin li").first().find("a").addClass("current");

slide = function(sens){
\$("#pagin li").hide();

for(t=startPage;t<incremSlide;t++){
\$("#pagin li").eq(t+1).show();
}
if(startPage == 0){
next.show();
prev.hide();
}else if(numberPage == totalSlidepPage ){
next.hide();
prev.show();
}else{
next.show();
prev.show();
}
}

showPage = function(page) {
\$(".line-content").hide();
\$(".line-content").each(function(n) {
if (n >= pageSize * (page - 1) && n < pageSize * page){
\$(this).show();
}
});
}

showPage(1);
\$("#pagin li a").eq(0).addClass("current");

\$("#pagin li a").click(function() {
\$("#pagin li a").removeClass("current");
\$(this).addClass("current");
showPage(parseInt(\$(this).text()));
});
</script>``````

Output:

Example:

In this example, we will create bootstrap pagination with help of jquery.

``````<!DOCTYPE html>
<html lang="en">
<head>
<title>How To Create Bootstrap Pagination Using jQuery - Websolutionstuff</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<style>
#data tr {
display: none;
}

.page {
margin: 30px;
}

table, th, td {
border: 1px solid black;
}

#data {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

#data td, #data th {
border: 1px solid #ddd;
padding: 8px;
}

#data tr:nth-child(even) {
background-color: #f2f2f2;
}

#data tr:hover {
background-color: #ddd;
}

#data th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #03aa96;
color: white;
}

#nav a {
color: #03aa96;
font-size: 20px;
margin-top: 22px;
font-weight: 600;
}

a:hover, a:visited, a:link, a:active {
text-decoration: none;
}

#nav {
margin-top: 20px;
}
</style>
</head>
<body>
<h2 align="center" class="mt-4">How To Create Bootstrap Pagination Using jQuery - Websolutionstuff</h2>
<div class="page" align="center">
<table id="data">
<tr>
<th>Id</th>
<th>Name</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>Maria</td>
<td>Germany</td>
</tr>
<tr>
<td>2</td>
<td>Christina</td>
<td>Sweden</td>
</tr>
<tr>
<td>3</td>
<td>Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>4</td>
<td>Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>5</td>
<td>Helen</td>
<td>United Kingdom</td>
</tr>
<tr>
<td>6</td>
<td>Philip</td>
<td>Germany</td>
</tr>
<tr>
<td>7</td>
<td>Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>8</td>
<td>Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>9</td>
<td>Dell</td>
<td>United Kingdom</td>
</tr>
<tr>
<td>10</td>
<td>Trump</td>
<td>France</td>
</tr>
</table>
</div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script>
\$(document).ready (function () {
\$('#data').after ('<div id="nav"></div>');
var rowsShown = 5;
var rowsTotal = \$('#data tbody tr').length;
var numPages = rowsTotal/rowsShown;
for (i = 0;i < numPages;i++) {
var pageNum = i + 1;
\$('#nav').append ('<a href="#" rel="'+i+'">'+pageNum+'</a> ');
}
\$('#data tbody tr').hide();
\$('#data tbody tr').slice (0, rowsShown).show();
\$('#nav a:first').addClass('active');
\$('#nav a').bind('click', function() {
\$('#nav a').removeClass('active');
\$(this).addClass('active');
var currPage = \$(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
\$('#data tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
});
</script>``````

Output:

Example:

In this example, we will create pagination using the twbsPagination plugin. This jQuery plugin simplifies the usage of Bootstrap Pagination.

``````<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Pagination Using Plugin - Websolutionstuff</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<style>
.wrapper{
margin: 60px auto;
text-align: center;
}
h2{
margin-bottom: 1.25em;
}

#pagination-demo{
display: inline-block;
margin-bottom: 1.75em;
}

#pagination-demo li{
display: inline-block;
}

.page-content{
background: #eee;
display: inline-block;
padding: 10px;
width: 100%;
max-width: 660px;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container">

<div class="row">
<div class="col-sm-12">
<h2>jQuery Pagination Using Plugin - Websolutionstuff</h2>
<p>Simple pagination using the TWBS pagination JS library.</p>
<ul id="pagination-demo" class="pagination-sm"></ul>
</div>
</div>

<div id="page-content" class="page-content">Page 1</div>
</div>
</div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twbs-pagination/1.4.1/jquery.twbsPagination.min.js"></script>
<script>
\$(document).ready (function () {
\$('#pagination-demo').twbsPagination({
totalPages: 16,
visiblePages: 6,
next: 'Next',
prev: 'Prev',
onPageClick: function (event, page) {
\$('#page-content').text('Page ' + page) + ' content here';
}
});
});
</script>``````

Output:

Original article source at: https://websolutionstuff.com/

1685213040

## 使用 jQuery 创建分页

``````<!DOCTYPE html>
<html lang="en">
<head>
<title>How To Create Pagination Using jQuery - Websolutionstuff</title>
<style>
.current {
color: green;
}

#pagin li {
display: inline-block;
font-weight: 500;
}

.prev {
cursor: pointer;
}

.next {
cursor: pointer;
}

.last {
cursor:pointer;
margin-left:10px;
}

.first {
cursor:pointer;
margin-right:10px;
}

.line-content, #pagin, h3 {
text-align:center;
}

.line-content {
margin-top:20px;
}

#pagin {
margin-top:10px;
padding-left:0;
}

h3 {
margin:50px 0;
}
</style>
</head>
<body>
<h3>How To Create Pagination Using jQuery - Websolutionstuff</h3>
<div class="line-content">This is Page 1 content example with next and prev.</div>
<div class="line-content">This is Page 2 content example with next and prev.</div>
<div class="line-content">This is Page 3 content example with next and prev.</div>
<div class="line-content">This is Page 4 content example with next and prev.</div>
<div class="line-content">This is Page 5 content example with next and prev.</div>
<div class="line-content">This is Page 6 content example with next and prev.</div>
<div class="line-content">This is Page 7 content example with next and prev.</div>
<div class="line-content">This is Page 8 content example with next and prev.</div>
<div class="line-content">This is Page 9 content example with next and prev.</div>
<div class="line-content">This is Page 10 content example with next and prev.</div>
<div class="line-content">This is Page 11 content example with next and prev.</div>
<div class="line-content">This is Page 12 content example with next and prev.</div>
<div class="line-content">This is Page 13 content example with next and prev.</div>
<div class="line-content">This is Page 14 content example with next and prev.</div>
<div class="line-content">This is Page 15 content example with next and prev.</div>
<div class="line-content">This is Page 16 content example with next and prev.</div>
<div class="line-content">This is Page 17 content example with next and prev.</div>
<div class="line-content">This is Page 18 content example with next and prev.</div>
<div class="line-content">This is Page 19 content example with next and prev.</div>
<div class="line-content">This is Page 20 content example with next and prev.</div>
<div class="line-content">This is Page 21 content example with next and prev.</div>
<div class="line-content">This is Page 22 content example with next and prev.</div>
<div class="line-content">This is Page 23 content example with next and prev.</div>
<div class="line-content">This is Page 24 content example with next and prev.</div>
<div class="line-content">This is Page 25 content example with next and prev.</div>
<div class="line-content">This is Page 26 content example with next and prev.</div>
<div class="line-content">This is Page 27 content example with next and prev.</div>
<div class="line-content">This is Page 28 content example with next and prev.</div>
<div class="line-content">This is Page 29 content example with next and prev.</div>
<div class="line-content">This is Page 30 content example with next and prev.</div>
<div class="line-content">This is Page 31 content example with next and prev.</div>
<div class="line-content">This is Page 32 content example with next and prev.</div>
<div class="line-content">This is Page 33 content example with next and prev.</div>
<div class="line-content">This is Page 34 content example with next and prev.</div>
<div class="line-content">This is Page 35 content example with next and prev.</div>
<div class="line-content">This is Page 36 content example with next and prev.</div>
<div class="line-content">This is Page 37 content example with next and prev.</div>
<div class="line-content">This is Page 38 content example with next and prev.</div>
<div class="line-content">This is Page 39 content example with next and prev.</div>
<div class="line-content">This is Page 40 content example with next and prev.</div>
<div class="line-content">This is Page 41 content example with next and prev.</div>
<div class="line-content">This is Page 42 content example with next and prev.</div>
<div class="line-content">This is Page 43 content example with next and prev.</div>
<div class="line-content">This is Page 44 content example with next and prev.</div>
<div class="line-content">This is Page 45 content example with next and prev.</div>
<ul id="pagin"></ul>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script>

pageSize = 5;
incremSlide = 5;
startPage = 0;
numberPage = 0;

var pageCount =  \$(".line-content").length / pageSize;
var totalSlidepPage = Math.floor(pageCount / incremSlide);

for(var i = 0 ; i<pageCount;i++){
\$("#pagin").append('<li><a href="#">'+(i+1)+'</a></li> ');
if(i>pageSize){
\$("#pagin li").eq(i).hide();
}
}

var prev = \$("<li/>").addClass("prev").html("Prev").click(function(){
startPage-=5;
incremSlide-=5;
numberPage--;
slide();
});

prev.hide();

var next = \$("<li/>").addClass("next").html("Next").click(function(){
startPage+=5;
incremSlide+=5;
numberPage++;
slide();
});

\$("#pagin").prepend(prev).append(next);

\$("#pagin li").first().find("a").addClass("current");

slide = function(sens){
\$("#pagin li").hide();

for(t=startPage;t<incremSlide;t++){
\$("#pagin li").eq(t+1).show();
}
if(startPage == 0){
next.show();
prev.hide();
}else if(numberPage == totalSlidepPage ){
next.hide();
prev.show();
}else{
next.show();
prev.show();
}
}

showPage = function(page) {
\$(".line-content").hide();
\$(".line-content").each(function(n) {
if (n >= pageSize * (page - 1) && n < pageSize * page){
\$(this).show();
}
});
}

showPage(1);
\$("#pagin li a").eq(0).addClass("current");

\$("#pagin li a").click(function() {
\$("#pagin li a").removeClass("current");
\$(this).addClass("current");
showPage(parseInt(\$(this).text()));
});
</script>``````

``````<!DOCTYPE html>
<html lang="en">
<head>
<title>How To Create Bootstrap Pagination Using jQuery - Websolutionstuff</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<style>
#data tr {
display: none;
}

.page {
margin: 30px;
}

table, th, td {
border: 1px solid black;
}

#data {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

#data td, #data th {
border: 1px solid #ddd;
padding: 8px;
}

#data tr:nth-child(even) {
background-color: #f2f2f2;
}

#data tr:hover {
background-color: #ddd;
}

#data th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #03aa96;
color: white;
}

#nav a {
color: #03aa96;
font-size: 20px;
margin-top: 22px;
font-weight: 600;
}

a:hover, a:visited, a:link, a:active {
text-decoration: none;
}

#nav {
margin-top: 20px;
}
</style>
</head>
<body>
<h2 align="center" class="mt-4">How To Create Bootstrap Pagination Using jQuery - Websolutionstuff</h2>
<div class="page" align="center">
<table id="data">
<tr>
<th>Id</th>
<th>Name</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>Maria</td>
<td>Germany</td>
</tr>
<tr>
<td>2</td>
<td>Christina</td>
<td>Sweden</td>
</tr>
<tr>
<td>3</td>
<td>Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>4</td>
<td>Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>5</td>
<td>Helen</td>
<td>United Kingdom</td>
</tr>
<tr>
<td>6</td>
<td>Philip</td>
<td>Germany</td>
</tr>
<tr>
<td>7</td>
<td>Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>8</td>
<td>Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>9</td>
<td>Dell</td>
<td>United Kingdom</td>
</tr>
<tr>
<td>10</td>
<td>Trump</td>
<td>France</td>
</tr>
</table>
</div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script>
\$(document).ready (function () {
\$('#data').after ('<div id="nav"></div>');
var rowsShown = 5;
var rowsTotal = \$('#data tbody tr').length;
var numPages = rowsTotal/rowsShown;
for (i = 0;i < numPages;i++) {
var pageNum = i + 1;
\$('#nav').append ('<a href="#" rel="'+i+'">'+pageNum+'</a> ');
}
\$('#data tbody tr').hide();
\$('#data tbody tr').slice (0, rowsShown).show();
\$('#nav a:first').addClass('active');
\$('#nav a').bind('click', function() {
\$('#nav a').removeClass('active');
\$(this).addClass('active');
var currPage = \$(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
\$('#data tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
});
</script>``````

``````<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Pagination Using Plugin - Websolutionstuff</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<style>
.wrapper{
margin: 60px auto;
text-align: center;
}
h2{
margin-bottom: 1.25em;
}

#pagination-demo{
display: inline-block;
margin-bottom: 1.75em;
}

#pagination-demo li{
display: inline-block;
}

.page-content{
background: #eee;
display: inline-block;
padding: 10px;
width: 100%;
max-width: 660px;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container">

<div class="row">
<div class="col-sm-12">
<h2>jQuery Pagination Using Plugin - Websolutionstuff</h2>
<p>Simple pagination using the TWBS pagination JS library.</p>
<ul id="pagination-demo" class="pagination-sm"></ul>
</div>
</div>

<div id="page-content" class="page-content">Page 1</div>
</div>
</div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twbs-pagination/1.4.1/jquery.twbsPagination.min.js"></script>
<script>
\$(document).ready (function () {
\$('#pagination-demo').twbsPagination({
totalPages: 16,
visiblePages: 6,
next: 'Next',
prev: 'Prev',
onPageClick: function (event, page) {
\$('#page-content').text('Page ' + page) + ' content here';
}
});
});
</script>``````

1685216760

## Создание пагинации с помощью jQuery

В этой статье мы увидим, как создать пагинацию с помощью jquery. Мы создадим разбиение на страницы jquery, используя несколько способов. Вы можете создать разбиение на страницы, используя разные способы, такие как создание разбиения на страницы с помощью простого HTML, вы можете создать разбиение на страницы в laravel, используя метод paginate(). Кроме того, создайте разбиение на страницы laravel livewire, разбиение на страницы с помощью бутстрапа.

Мы создадим простую пагинацию jquery. Кроме того, создайте разбиение на страницы с помощью jquery без плагина и создайте разбивку на страницы jquery с помощью кнопок «Далее» и «Предыдущий».

Итак, давайте посмотрим динамическую нумерацию страниц в jquery и бутстраповскую нумерацию страниц в jquery.

Пример:

В этом примере мы создадим пагинацию с помощью jquery без использования плагина. Кроме того, вы можете настроить пагинацию.

``````<!DOCTYPE html>
<html lang="en">
<head>
<title>How To Create Pagination Using jQuery - Websolutionstuff</title>
<style>
.current {
color: green;
}

#pagin li {
display: inline-block;
font-weight: 500;
}

.prev {
cursor: pointer;
}

.next {
cursor: pointer;
}

.last {
cursor:pointer;
margin-left:10px;
}

.first {
cursor:pointer;
margin-right:10px;
}

.line-content, #pagin, h3 {
text-align:center;
}

.line-content {
margin-top:20px;
}

#pagin {
margin-top:10px;
padding-left:0;
}

h3 {
margin:50px 0;
}
</style>
</head>
<body>
<h3>How To Create Pagination Using jQuery - Websolutionstuff</h3>
<div class="line-content">This is Page 1 content example with next and prev.</div>
<div class="line-content">This is Page 2 content example with next and prev.</div>
<div class="line-content">This is Page 3 content example with next and prev.</div>
<div class="line-content">This is Page 4 content example with next and prev.</div>
<div class="line-content">This is Page 5 content example with next and prev.</div>
<div class="line-content">This is Page 6 content example with next and prev.</div>
<div class="line-content">This is Page 7 content example with next and prev.</div>
<div class="line-content">This is Page 8 content example with next and prev.</div>
<div class="line-content">This is Page 9 content example with next and prev.</div>
<div class="line-content">This is Page 10 content example with next and prev.</div>
<div class="line-content">This is Page 11 content example with next and prev.</div>
<div class="line-content">This is Page 12 content example with next and prev.</div>
<div class="line-content">This is Page 13 content example with next and prev.</div>
<div class="line-content">This is Page 14 content example with next and prev.</div>
<div class="line-content">This is Page 15 content example with next and prev.</div>
<div class="line-content">This is Page 16 content example with next and prev.</div>
<div class="line-content">This is Page 17 content example with next and prev.</div>
<div class="line-content">This is Page 18 content example with next and prev.</div>
<div class="line-content">This is Page 19 content example with next and prev.</div>
<div class="line-content">This is Page 20 content example with next and prev.</div>
<div class="line-content">This is Page 21 content example with next and prev.</div>
<div class="line-content">This is Page 22 content example with next and prev.</div>
<div class="line-content">This is Page 23 content example with next and prev.</div>
<div class="line-content">This is Page 24 content example with next and prev.</div>
<div class="line-content">This is Page 25 content example with next and prev.</div>
<div class="line-content">This is Page 26 content example with next and prev.</div>
<div class="line-content">This is Page 27 content example with next and prev.</div>
<div class="line-content">This is Page 28 content example with next and prev.</div>
<div class="line-content">This is Page 29 content example with next and prev.</div>
<div class="line-content">This is Page 30 content example with next and prev.</div>
<div class="line-content">This is Page 31 content example with next and prev.</div>
<div class="line-content">This is Page 32 content example with next and prev.</div>
<div class="line-content">This is Page 33 content example with next and prev.</div>
<div class="line-content">This is Page 34 content example with next and prev.</div>
<div class="line-content">This is Page 35 content example with next and prev.</div>
<div class="line-content">This is Page 36 content example with next and prev.</div>
<div class="line-content">This is Page 37 content example with next and prev.</div>
<div class="line-content">This is Page 38 content example with next and prev.</div>
<div class="line-content">This is Page 39 content example with next and prev.</div>
<div class="line-content">This is Page 40 content example with next and prev.</div>
<div class="line-content">This is Page 41 content example with next and prev.</div>
<div class="line-content">This is Page 42 content example with next and prev.</div>
<div class="line-content">This is Page 43 content example with next and prev.</div>
<div class="line-content">This is Page 44 content example with next and prev.</div>
<div class="line-content">This is Page 45 content example with next and prev.</div>
<ul id="pagin"></ul>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script>

pageSize = 5;
incremSlide = 5;
startPage = 0;
numberPage = 0;

var pageCount =  \$(".line-content").length / pageSize;
var totalSlidepPage = Math.floor(pageCount / incremSlide);

for(var i = 0 ; i<pageCount;i++){
\$("#pagin").append('<li><a href="#">'+(i+1)+'</a></li> ');
if(i>pageSize){
\$("#pagin li").eq(i).hide();
}
}

var prev = \$("<li/>").addClass("prev").html("Prev").click(function(){
startPage-=5;
incremSlide-=5;
numberPage--;
slide();
});

prev.hide();

var next = \$("<li/>").addClass("next").html("Next").click(function(){
startPage+=5;
incremSlide+=5;
numberPage++;
slide();
});

\$("#pagin").prepend(prev).append(next);

\$("#pagin li").first().find("a").addClass("current");

slide = function(sens){
\$("#pagin li").hide();

for(t=startPage;t<incremSlide;t++){
\$("#pagin li").eq(t+1).show();
}
if(startPage == 0){
next.show();
prev.hide();
}else if(numberPage == totalSlidepPage ){
next.hide();
prev.show();
}else{
next.show();
prev.show();
}
}

showPage = function(page) {
\$(".line-content").hide();
\$(".line-content").each(function(n) {
if (n >= pageSize * (page - 1) && n < pageSize * page){
\$(this).show();
}
});
}

showPage(1);
\$("#pagin li a").eq(0).addClass("current");

\$("#pagin li a").click(function() {
\$("#pagin li a").removeClass("current");
\$(this).addClass("current");
showPage(parseInt(\$(this).text()));
});
</script>``````

Выход:

Пример:

В этом примере мы создадим загрузочную пагинацию с помощью jquery.

``````<!DOCTYPE html>
<html lang="en">
<head>
<title>How To Create Bootstrap Pagination Using jQuery - Websolutionstuff</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<style>
#data tr {
display: none;
}

.page {
margin: 30px;
}

table, th, td {
border: 1px solid black;
}

#data {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

#data td, #data th {
border: 1px solid #ddd;
padding: 8px;
}

#data tr:nth-child(even) {
background-color: #f2f2f2;
}

#data tr:hover {
background-color: #ddd;
}

#data th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #03aa96;
color: white;
}

#nav a {
color: #03aa96;
font-size: 20px;
margin-top: 22px;
font-weight: 600;
}

a:hover, a:visited, a:link, a:active {
text-decoration: none;
}

#nav {
margin-top: 20px;
}
</style>
</head>
<body>
<h2 align="center" class="mt-4">How To Create Bootstrap Pagination Using jQuery - Websolutionstuff</h2>
<div class="page" align="center">
<table id="data">
<tr>
<th>Id</th>
<th>Name</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>Maria</td>
<td>Germany</td>
</tr>
<tr>
<td>2</td>
<td>Christina</td>
<td>Sweden</td>
</tr>
<tr>
<td>3</td>
<td>Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>4</td>
<td>Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>5</td>
<td>Helen</td>
<td>United Kingdom</td>
</tr>
<tr>
<td>6</td>
<td>Philip</td>
<td>Germany</td>
</tr>
<tr>
<td>7</td>
<td>Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>8</td>
<td>Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>9</td>
<td>Dell</td>
<td>United Kingdom</td>
</tr>
<tr>
<td>10</td>
<td>Trump</td>
<td>France</td>
</tr>
</table>
</div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script>
\$(document).ready (function () {
\$('#data').after ('<div id="nav"></div>');
var rowsShown = 5;
var rowsTotal = \$('#data tbody tr').length;
var numPages = rowsTotal/rowsShown;
for (i = 0;i < numPages;i++) {
var pageNum = i + 1;
\$('#nav').append ('<a href="#" rel="'+i+'">'+pageNum+'</a> ');
}
\$('#data tbody tr').hide();
\$('#data tbody tr').slice (0, rowsShown).show();
\$('#nav a:first').addClass('active');
\$('#nav a').bind('click', function() {
\$('#nav a').removeClass('active');
\$(this).addClass('active');
var currPage = \$(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
\$('#data tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
});
</script>``````

Выход:

Пример:

В этом примере мы создадим пагинацию с помощью плагина twbsPagination . Этот плагин jQuery упрощает использование разбиения на страницы Bootstrap.

``````<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Pagination Using Plugin - Websolutionstuff</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<style>
.wrapper{
margin: 60px auto;
text-align: center;
}
h2{
margin-bottom: 1.25em;
}

#pagination-demo{
display: inline-block;
margin-bottom: 1.75em;
}

#pagination-demo li{
display: inline-block;
}

.page-content{
background: #eee;
display: inline-block;
padding: 10px;
width: 100%;
max-width: 660px;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container">

<div class="row">
<div class="col-sm-12">
<h2>jQuery Pagination Using Plugin - Websolutionstuff</h2>
<p>Simple pagination using the TWBS pagination JS library.</p>
<ul id="pagination-demo" class="pagination-sm"></ul>
</div>
</div>

<div id="page-content" class="page-content">Page 1</div>
</div>
</div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twbs-pagination/1.4.1/jquery.twbsPagination.min.js"></script>
<script>
\$(document).ready (function () {
\$('#pagination-demo').twbsPagination({
totalPages: 16,
visiblePages: 6,
next: 'Next',
prev: 'Prev',
onPageClick: function (event, page) {
\$('#page-content').text('Page ' + page) + ' content here';
}
});
});
</script>``````

Выход:

Оригинальный источник статьи: https://websolutionstuff.com/