Skip to main content

Pagination
New

This template shows how to build a simple paginated page

Hint: Press F on your keyboard to view both templates and components in fullscreen and ESC to exit the fullscreen mode. You can also open the template in a new browser window.


Open in new window
<!DOCTYPE html>
<html class="duet-bg-gradient duet-sticky-footer" lang="fi">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>LähiTapiola</title>
<link rel="stylesheet" href="https://cdn.duetds.com/api/fonts/1.4.37/lib/localtapiola.css" integrity="sha384-5JYmtSD7nykpUvSmTW1CHMoBDkBZUpUmG0vuh+NUVtZag3F75Kr7+/JU3J7JV6Wq" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdn.duetds.com/api/css/1.7.39/lib/duet.min.css" integrity="sha384-ZUOdWRfXRTVZwK0KKDUx+7tNxj3LaOXhNpoLH/p42gaIO2HuzLY8CyPU38wbFmvV" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdn.duetds.com/api/tokens/2.5.20/lib/tokens.custom-properties.css" integrity="sha384-U+lBqX3FeAku5Wet1UsKbPE9qCtnuXTTlXft7791G1hswVrwpRaviO5rey2lm8Dz" crossorigin="anonymous" />
<script type="module" src="https://cdn.duetds.com/api/components/5.3.1/lib/duet/duet.esm.js" integrity="sha384-nUksWwJI0U+G4Nru/BbdCflbk//IcAuPp/ilnvBt5K0dgCHzp+jIAbhL2bBC68qH" crossorigin="anonymous"></script>
<script nomodule src="https://cdn.duetds.com/api/components/5.3.1/lib/duet/duet.js" integrity="sha384-Sm4kyV3SeYJab7OqmsB26Lul42KU/1uaa/bDvq13J/Z2pPrI7XieeBYckyNIfUe7" crossorigin="anonymous"></script>
</head>
<body>
<style>
.duet-dummy-placeholder {
height: 170px;
width: 150px;
background-color: #fff;
border: 1px solid #ccc;
min-width: 200px;
font-size: 50px;
color: #c3c3c3;
}

.pagination-advanced {
text-align: center;
margin: 0 auto;
}

.pagination-advanced .pagination-menu {
display: grid;
grid-auto-flow: column;
grid-auto-columns: minmax(300px, 600px) minmax(100px, 300px) minmax(100px, 150px);
grid-template-rows: 1fr;
gap: 0px 0px;
grid-template-areas: "pager ranger select";
justify-content: start;
align-content: center;
justify-items: baseline;
align-items: center;
}

.pagination-advanced .pagination-menu duet-pagination {
grid-area: pager;
justify-self: start;
align-self: center;
width: 100%;
}

.pagination-advanced .pagination-menu duet-range-stepper {
justify-self: end;
align-self: center;
grid-area: ranger;
}

.pagination-advanced .pagination-menu duet-select {
justify-self: end;
align-self: center;
grid-area: select;
}

@media only screen and (max-width: 48em) {
.pagination-advanced .pagination-menu {
display: block;
}

duet-range-stepper {
display: none;
}

duet-select {
display: none !important;
}
}
</style>

<duet-header language="fi" skip-to-id="#content" contact="Ota yhteyttä" current-href="/"></duet-header>

<duet-layout id="content">
<div slot="main">
<duet-card padding="large" heading="Plain with footer">
<duet-table variation="plain" breakpoint="medium">
<table>
<thead>
<tr>
<th>Nostokohde</th>
<th>Arvopäivä</th>
<th>Nosto-%</th>
<th class="duet-text-right">Nosto</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name of original asset</td>
<td>16.04.2019</td>
<td>5&nbsp;%</td>
<td class="duet-text-right">-1&nbsp;000,00&nbsp;</td>
</tr>
<tr>
<td>Name of original asset</td>
<td>16.04.2019</td>
<td>12&nbsp;%</td>
<td class="duet-text-right">-1&nbsp;000,00&nbsp;</td>
</tr>
<tr>
<td>Name of original asset</td>
<td>16.04.2019</td>
<td>5&nbsp;%</td>
<td class="duet-text-right">-1&nbsp;000,00&nbsp;</td>
</tr>
<tr>
<td>Name of original asset</td>
<td>16.04.2019</td>
<td>12&nbsp;%</td>
<td class="duet-text-right">-1&nbsp;000,00&nbsp;</td>
</tr>
<tr>
<td>Name of original asset</td>
<td>16.04.2019</td>
<td>5&nbsp;%</td>
<td class="duet-text-right">-1&nbsp;000,00&nbsp;</td>
</tr>
<tr>
<td>Name of original asset</td>
<td>16.04.2019</td>
<td>12&nbsp;%</td>
<td class="duet-text-right">-1&nbsp;000,00&nbsp;</td>
</tr>
<tr>
<td>Name of original asset</td>
<td>16.04.2019</td>
<td>5&nbsp;%</td>
<td class="duet-text-right">-1&nbsp;000,00&nbsp;</td>
</tr>
<tr>
<td>Name of original asset</td>
<td>16.04.2019</td>
<td>12&nbsp;%</td>
<td class="duet-text-right">-1&nbsp;000,00&nbsp;</td>
</tr>
<tr>
<td>Name of original asset</td>
<td>16.04.2019</td>
<td>32&nbsp;%</td>
<td class="duet-text-right">-500,00&nbsp;</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colSpan="4" class="duet-font-weight-semi-bold pagination-advanced">
<div class="pagination-menu">
<duet-pagination take="50" visible-items="5" total="1000"></duet-pagination>
<duet-range-stepper step-size="50" total="1000" step-index="1"></duet-range-stepper
>

<duet-select label-hidden label="select range" value="10" variation="tiny"></duet-select>
</div>
</td>
</tr>
</tfoot>
</table>
</duet-table>
</duet-card>
</div>
</duet-layout>
<duet-footer logo-href="/" language="fi"></duet-footer>
<script>
// Save references to components we want to adjust below
var header = document.querySelector("duet-header")
var footer = document.querySelector("duet-footer")

// Set the contact menu items
header.contactItems = [
{ label: "Kysy lisätietoja", href: "mailto:minna.poikela@lahitapiola.fi" },
{ label: "Yhteystiedot", href: "/yhteystiedot/" }
]

// Set label and href for session link
header.session = {
label: "Kirjaudu sisään",
href: "#signin",
type: "signin"
}

// Set footer main items
footer.items = [
{ label: 'Hae korvausta', href: '#', icon: 'navigation-make-claim' },
{ label: 'Osta vakuutus', href: '#', icon: 'action-buy-insurance' },
{ label: 'Yhteystiedot', href: '#', icon: 'form-tel' }
]

// Set footer help menu
footer.menu = [
{ label: 'Turvallisuus ja käyttöehdot', href: '#' },
{ label: 'Evästeet', href: '#' },
{ label: 'Henkilötietojen käsittely', href: '#' },
]

// Save a reference to the above pagination components
const select = document.querySelector("duet-select")
const pagination = document.querySelector("duet-pagination")
const range = document.querySelector("duet-range-stepper")

// Set select menu items and their values
select.items = [
{ label: "10", value: "10" },
{ label: "20", value: "20" },
{ label: "30", value: "30" },
{ label: "40", value: "40" },
{ label: "50", value: "50" },
]

// try to get take from url
const urlTake = getHash(location.hash, "take") || "50"
select.setAttribute("value", urlTake)
pagination.setAttribute("take", urlTake)
range.setAttribute("step-size", urlTake)

// try to get current page from url
const currPage = getHash(location.hash, "page") || "1"
range.setAttribute("step-index", currPage)
pagination.setAttribute("current", currPage)

// Listen for change events in the select
select.addEventListener("duetChange", function(e) {
console.log("Change event detected in select:", e.detail)
pagination.setAttribute("take", e.detail.value)
location.hash = setHash(location.hash, "take", e.detail.value)

//assuming you'd want to reset your position when changing the take
location.hash = deleteHash(location.hash, "page")

//simulate a new pageload (you should either load or use pushState when user changes settings like these)
document.location.reload()
})

// Listen for change events in the pager
pagination.addEventListener("duetPageChange", function(e) {
console.log("Change event detected in pagination:", e.detail)
range.setAttribute("step-index", e.detail.current)
})

// Listen for change events in the ranger
range.addEventListener("duetRangeStepUpdate", function(e) {
console.log("Change event detected in ranger:", e.detail, location.hash)
location.hash = setHash(location.hash, "page", e.detail.index)
pagination.setAttribute("current", e.detail.index)
})

//Simple JS url hashing functions
function getHash(hash, key) {
return hash
.split("#")
.find((h) => h.startsWith(key))
?.replace(`${key}=`, "");
}

function setHash(hash, key, value) {
let hashArray = hash.split("#").filter((h) => !h.startsWith(key));
hashArray.push(`${key}=${value}`);
return hashArray.length > 0
? hashArray.reduce((s1, s2) => `${s1}#${s2}`)
: "";
}

function deleteHash(hash, key) {
let hashArray = hash.split("#").filter((h) => !h.startsWith(key));
return hashArray.length > 0
? hashArray.reduce((s1, s2) => `${s1}#${s2}`)
: "";
}
</script>
</body>
</html>

Integration

To install this template’s dependencies into your project, run:

npm install @duetds/components
npm install @duetds/css
npm install @duetds/fonts

For further guidelines, please see each package’s documentation.



Tutorials

Follow these practical tutorials to learn how to build simple page layouts using Duet’s CSS Framework, Web Components and other features:

Tutorials

Building Layouts

Tutorials

Using CLI Tools

Tutorials

Creating Custom Patterns

Tutorials

Server Side Rendering

Tutorials

Sharing Prototypes

Tutorials

Usage With Markdown

Tutorials

Zeplin


Troubleshooting

If you experience any issues while using a template, please head over to the Support page for more guidelines and help.