302 lines
12 KiB
Vue
Executable File
302 lines
12 KiB
Vue
Executable File
<template>
|
|
<div class="content-section documentation">
|
|
<TabView>
|
|
<TabPanel header="Documentation">
|
|
<h3>Import</h3>
|
|
<CodeHighlight lang="javascript">
|
|
import Paginator from 'primevue/paginator';
|
|
</CodeHighlight>
|
|
|
|
<h3>Getting Started</h3>
|
|
<p><i>rows</i> and <i>totalRecords</i> are the required properties of the Paginator.</p>
|
|
<CodeHighlight>
|
|
<Paginator :rows="10" :totalRecords="totalItemsCount"></Paginator>
|
|
</CodeHighlight>
|
|
|
|
<h3>Start Index</h3>
|
|
<p><i>first</i> property defines the index of the first item displayed by the paginator.</p>
|
|
|
|
<CodeHighlight>
|
|
<Paginator :first="offset" :rows="10" :totalRecords="totalItemsCount"></Paginator>
|
|
</CodeHighlight>
|
|
|
|
<p>Use the sync operator to enable two-way binding, this is useful in cases where you need to programmatically control the paginator.</p>
|
|
<CodeHighlight>
|
|
<Paginator :first.sync="offset" :rows="10" :totalRecords="totalItemsCount"></Paginator>
|
|
</CodeHighlight>
|
|
|
|
<h3>Rows Per Page</h3>
|
|
<p>Number of items per page can be changed by the user using a dropdown with the <i>rowsPerPageOptions</i> property which accepts an array of possible values.</p>
|
|
<CodeHighlight>
|
|
<Paginator :first.sync="offset" :rows="rows" :totalRecords="totalItemsCount" :rowsPerPageOptions="[10,20,30]"></Paginator>
|
|
</CodeHighlight>
|
|
|
|
<p>As <i>rows</i> also change when the dropdown changes, use the optional sync operator if you need two-way binding.</p>
|
|
|
|
<CodeHighlight>
|
|
<Paginator :first.sync="offset" :rows.sync="rows" :totalRecords="totalItemsCount" :rowsPerPageOptions="[10,20,30]"></Paginator>
|
|
</CodeHighlight>
|
|
|
|
<h3>Template</h3>
|
|
<p>Paginator elements can be customized using the template property using the predefined keys, default value is
|
|
"FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown". Here are the available elements that
|
|
can be placed inside a paginator in any order.</p>
|
|
|
|
<ul>
|
|
<li>FirstPageLink</li>
|
|
<li>PrevPageLink</li>
|
|
<li>PageLinks</li>
|
|
<li>NextPageLink</li>
|
|
<li>LastPageLink</li>
|
|
<li>RowsPerPageDropdown</li>
|
|
<li>CurrentPageReport</li>
|
|
</ul>
|
|
|
|
<h3>CurrentPageReport</h3>
|
|
<p>Current page report item in the template displays information about the pagination state. Default value is ({currentPage} of {totalPages})
|
|
whereas available placeholders are the following;
|
|
</p>
|
|
<ul>
|
|
<li>{currentPage}</li>
|
|
<li>{totalPages}</li>
|
|
<li>{rows}</li>
|
|
<li>{first}</li>
|
|
<li>{last}</li>
|
|
<li>{totalRecords}</li>
|
|
</ul>
|
|
|
|
<h3>Custom Content</h3>
|
|
<p>There are two templates available named "left" and "right" to add custom content to these locations. Both templates get
|
|
a state object as a slot property to provide the current page, first index and the rows.
|
|
</p>
|
|
<CodeHighlight>
|
|
<template v-pre>
|
|
<Paginator :first.sync="offset" :rows="10" :totalRecords="totalItemsCount">
|
|
<template #left="slotProps">
|
|
Page: {{slotProps.state.page}}
|
|
First: {{slotProps.state.first}}
|
|
Rows: {{slotProps.state.rows}}
|
|
</template>
|
|
<template #right>
|
|
<Button type="button" icon="pi pi-search" />
|
|
</template>
|
|
</Paginator>
|
|
</template>
|
|
</CodeHighlight>
|
|
|
|
<h3>Page Change Event</h3>
|
|
<p>Paginator provides only one event called <i>page</i> that passes all the information about the change event.</p>
|
|
<CodeHighlight>
|
|
<Paginator :rows="10" :totalRecords="totalItemsCount" @page="onPage($event)"></Paginator>
|
|
</CodeHighlight>
|
|
|
|
<CodeHighlight lang="javascript">
|
|
onPage(event) {
|
|
//event.page: New page number
|
|
//event.first: Index of first record
|
|
//event.rows: Number of rows to display in new page
|
|
//event.pageCount: Total number of pages
|
|
}
|
|
</CodeHighlight>
|
|
|
|
<h3>Properties</h3>
|
|
<div class="doc-tablewrapper">
|
|
<table class="doc-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>totalRecords</td>
|
|
<td>number</td>
|
|
<td>0</td>
|
|
<td>Number of total records.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>rows</td>
|
|
<td>number</td>
|
|
<td>0</td>
|
|
<td>Data count to display per page.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>first</td>
|
|
<td>number</td>
|
|
<td>0</td>
|
|
<td>Zero-relative number of the first row to be displayed.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>pageLinkSize</td>
|
|
<td>number</td>
|
|
<td>5</td>
|
|
<td>Number of page links to display.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>rowsPerPageOptions</td>
|
|
<td>array</td>
|
|
<td>null</td>
|
|
<td>Array of integer values to display inside rows per page dropdown.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>template</td>
|
|
<td>string</td>
|
|
<td>FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown</td>
|
|
<td>Template of the paginator.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>currentPageReportTemplate</td>
|
|
<td>string</td>
|
|
<td>({currentPage} of {totalPages})</td>
|
|
<td>Template of the current page report element. Available placeholders are
|
|
{currentPage},{totalPages},{rows},{first},{last} and {totalRecords}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>alwaysShow</td>
|
|
<td>boolean</td>
|
|
<td>true</td>
|
|
<td>Whether to show the paginator even there is only one page.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h3>Events</h3>
|
|
<div class="doc-tablewrapper">
|
|
<table class="doc-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Parameters</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>page</td>
|
|
<td>event.page: New page number <br/>
|
|
event.first: Index of first record <br/>
|
|
event.rows: Number of rows to display in new page <br/>
|
|
event.pageCount: Total number of pages
|
|
</td>
|
|
<td>Callback to invoke when page changes, the event object contains information about the new state.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h3>Styling</h3>
|
|
<p>Following is the list of structural style classes, for theming classes visit <router-link to="/theming">theming</router-link> page.</p>
|
|
<div class="doc-tablewrapper">
|
|
<table class="doc-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Element</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>p-paginator</td>
|
|
<td>Container element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-paginator-first</td>
|
|
<td>First page element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-paginator-prev</td>
|
|
<td>Previous page element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-paginator-pages</td>
|
|
<td>Container of page links.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-paginator-page</td>
|
|
<td>A page link.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-paginator-next</td>
|
|
<td>Next pge element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-paginator-last</td>
|
|
<td>Last page element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-paginator-rpp-options</td>
|
|
<td>Rows per page dropdown.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h3>Dependencies</h3>
|
|
<p>None.</p>
|
|
</div>
|
|
</TabPanel>
|
|
|
|
<TabPanel header="Source">
|
|
<a href="https://github.com/primefaces/primereact/tree/master/src/showcase/paginator" class="btn-viewsource" target="_blank" rel="noopener noreferrer">
|
|
<span>View on GitHub</span>
|
|
</a>
|
|
<CodeHighlight>
|
|
<h3>Basic</h3>
|
|
<Paginator :rows="10" :totalRecords="totalRecords" :rowsPerPageOptions="[10,20,30]"></Paginator>
|
|
|
|
<h3>Custom</h3>
|
|
<Paginator :first.sync="first" :rows="1" :totalRecords="totalRecords2"
|
|
template="FirstPageLink PrevPageLink CurrentPageReport NextPageLink LastPageLink">
|
|
<template #left>
|
|
<Button type="button" icon="pi pi-refresh" @click="reset()"/>
|
|
</template>
|
|
<template #right>
|
|
<Button type="button" icon="pi pi-search" />
|
|
</template>
|
|
</Paginator>
|
|
|
|
<div class="image-gallery">
|
|
<img :src="'demo/images/nature/' + image + '.jpg'" />
|
|
</div>
|
|
</CodeHighlight>
|
|
|
|
<CodeHighlight lang="javascript">
|
|
export default {
|
|
data() {
|
|
return {
|
|
first: 0,
|
|
totalRecords: 120,
|
|
totalRecords2: 12
|
|
}
|
|
},
|
|
methods: {
|
|
reset() {
|
|
this.first = 0;
|
|
}
|
|
},
|
|
computed: {
|
|
image() {
|
|
return 'nature' + (this.first + 1);
|
|
}
|
|
}
|
|
}
|
|
</CodeHighlight>
|
|
|
|
<CodeHighlight lang="css">
|
|
.p-button.p-button-icon-only {
|
|
border-radius: 0;
|
|
}
|
|
|
|
.image-gallery {
|
|
text-align: center;
|
|
padding: 1rem;
|
|
}
|
|
</CodeHighlight>
|
|
</TabPanel>
|
|
</TabView>
|
|
</div>
|
|
</template> |