pull/12/head
onursenture 2019-03-20 15:39:58 +03:00
commit 33b4752560
3 changed files with 331 additions and 334 deletions

View File

@ -13,146 +13,144 @@
</template> </template>
<script> <script>
import CurrrentPageReport from './CurrentPageReport'; import CurrrentPageReport from './CurrentPageReport';
import FirstPageLink from './FirstPageLink'; import FirstPageLink from './FirstPageLink';
import LastPageLink from './LastPageLink'; import LastPageLink from './LastPageLink';
import NextPageLink from './NextPageLink'; import NextPageLink from './NextPageLink';
import PageLinks from './PageLinks'; import PageLinks from './PageLinks';
import PrevPageLink from './PrevPageLink'; import PrevPageLink from './PrevPageLink';
import RowsPerPageDropdown from './RowsPerPageDropdown'; import RowsPerPageDropdown from './RowsPerPageDropdown';
export default { export default {
props: { props: {
totalRecords: { totalRecords: {
type: Number, type: Number,
default: 0 default: 0
}, },
rows: { rows: {
type: Number, type: Number,
default: 0 default: 0
}, },
first: { first: {
type: Number, type: Number,
default: 0 default: 0
}, },
pageLinkSize: { pageLinkSize: {
type: Number, type: Number,
default: 5 default: 5
}, },
rowsPerPageOptions: Array, rowsPerPageOptions: Array,
template: { template: {
type: String, type: String,
default: 'FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown' default: 'FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown'
}, },
leftContent: null, currentPageReportTemplate: {
rightContent: null, type: null,
currentPageReportTemplate: { default: '({currentPage} of {totalPages})'
type: null, }
default: '({currentPage} of {totalPages})' },
} components: {
}, 'CurrentPageReport': CurrrentPageReport,
components: { 'FirstPageLink': FirstPageLink,
'CurrentPageReport': CurrrentPageReport, 'LastPageLink': LastPageLink,
'FirstPageLink': FirstPageLink, 'NextPageLink': NextPageLink,
'LastPageLink': LastPageLink, 'PageLinks': PageLinks,
'NextPageLink': NextPageLink, 'PrevPageLink': PrevPageLink,
'PageLinks': PageLinks, 'RowsPerPageDropdown': RowsPerPageDropdown,
'PrevPageLink': PrevPageLink, },
'RowsPerPageDropdown': RowsPerPageDropdown, computed: {
}, templateItems() {
computed: { var keys = [];
templateItems() { this.template.split(' ').map((value) => {
var keys = []; keys.push(value.trim());
this.template.split(' ').map((value) => { })
keys.push(value.trim()); return keys;
}) },
return keys; page() {
}, return Math.floor(this.first / this.rows);
page() { },
return Math.floor(this.first / this.rows);
},
pageCount() { pageCount() {
return Math.ceil(this.totalRecords / this.rows) || 1; return Math.ceil(this.totalRecords / this.rows) || 1;
}, },
isFirstPage() { isFirstPage() {
return this.page === 0; return this.page === 0;
}, },
isLastPage() { isLastPage() {
return this.page === this.pageCount - 1; return this.page === this.pageCount - 1;
}, },
calculatePageLinkBoundaries() { calculatePageLinkBoundaries() {
var numberOfPages = this.pageCount; var numberOfPages = this.pageCount;
var visiblePages = Math.min(this.pageLinkSize, numberOfPages); var visiblePages = Math.min(this.pageLinkSize, numberOfPages);
//calculate range, keep current in middle if necessary //calculate range, keep current in middle if necessary
var start = Math.max(0, Math.ceil(this.page - ((visiblePages) / 2))); var start = Math.max(0, Math.ceil(this.page - ((visiblePages) / 2)));
var end = Math.min(numberOfPages - 1, start + visiblePages - 1); var end = Math.min(numberOfPages - 1, start + visiblePages - 1);
//check when approaching to last page //check when approaching to last page
var delta = this.pageLinkSize - (end - start + 1); var delta = this.pageLinkSize - (end - start + 1);
start = Math.max(0, start - delta); start = Math.max(0, start - delta);
return [start, end]; return [start, end];
}, },
updatePageLinks() { updatePageLinks() {
var pageLinks = []; var pageLinks = [];
var boundaries = this.calculatePageLinkBoundaries; var boundaries = this.calculatePageLinkBoundaries;
var start = boundaries[0]; var start = boundaries[0];
var end = boundaries[1]; var end = boundaries[1];
for(var i = start; i <= end; i++) { for(var i = start; i <= end; i++) {
pageLinks.push(i + 1); pageLinks.push(i + 1);
} }
return pageLinks; return pageLinks;
} }
}, },
methods: { methods: {
changePage(first, rows) { changePage(first, rows) {
var pc = this.pageCount; var pc = this.pageCount;
var p = Math.floor(first / rows); var p = Math.floor(first / rows);
if(p >= 0 && p < pc) { if(p >= 0 && p < pc) {
var newPageState = { var newPageState = {
first: first, first: first,
rows: rows, rows: rows,
page: p, page: p,
pageCount: pc pageCount: pc
}; };
this.$emit('change', newPageState); this.$emit('change', newPageState);
} }
}, },
changePageToFirst(event) { changePageToFirst(event) {
this.changePage(0, this.rows); this.changePage(0, this.rows);
event.preventDefault(); event.preventDefault();
}, },
changePageToPrev(event) { changePageToPrev(event) {
this.changePage(this.first - this.rows, this.rows); this.changePage(this.first - this.rows, this.rows);
event.preventDefault(); event.preventDefault();
}, },
pageLinkClick(event) { pageLinkClick(event) {
this.changePage((event.value - 1) * this.rows, this.rows); this.changePage((event.value - 1) * this.rows, this.rows);
}, },
changePageToNext(event) { changePageToNext(event) {
this.changePage(this.first + this.rows, this.rows); this.changePage(this.first + this.rows, this.rows);
event.preventDefault(); event.preventDefault();
}, },
changePageToLast(event) { changePageToLast(event) {
this.changePage((this.pageCount - 1) * this.rows, this.rows); this.changePage((this.pageCount - 1) * this.rows, this.rows);
event.preventDefault(); event.preventDefault();
}, },
rowsChange(event) { rowsChange(event) {
this.changePage(0, event.value.code); this.changePage(0, event.value.code);
} }
} }
} }
</script> </script>

View File

@ -3,7 +3,7 @@
<div class="content-section introduction"> <div class="content-section introduction">
<div class="feature-intro"> <div class="feature-intro">
<h1>Paginator</h1> <h1>Paginator</h1>
<p>Paginator is a generic widget to display content in paged format.</p> <p>Paginator is a generic component to display content in paged format.</p>
</div> </div>
</div> </div>
@ -20,34 +20,31 @@
</template> </template>
<script> <script>
import PaginatorDoc from './PaginatorDoc'; import PaginatorDoc from './PaginatorDoc';
export default { export default {
data() { data() {
return { return {
first: 0, first: 0,
rows: 10, rows: 10,
totalRecords: 50, totalRecords: 50,
first2: 0, first2: 0,
rows2: 1, rows2: 1,
totalRecords2: 12 totalRecords2: 12
}
},
methods: {
onPageChange(event) {
this.first = event.first;
this.rows = event.rows;
},
onPageChangeCustom(event) {
this.first2 = event.first;
this.rows2 = event.rows;
}
},
components: {
'PaginatorDoc': PaginatorDoc
} }
} },
methods: {
onPageChange(event) {
this.first = event.first;
this.rows = event.rows;
},
onPageChangeCustom(event) {
this.first2 = event.first;
this.rows2 = event.rows;
}
},
components: {
'PaginatorDoc': PaginatorDoc
}
}
</script> </script>
<style lang="scss">
</style>

View File

@ -1,196 +1,198 @@
<template> <template>
<div class="content-section documentation"> <div class="content-section documentation">
<TabView> <TabView>
<TabPanel header="Documentation"> <TabPanel header="Documentation">
<h3>Import</h3> <h3>Import</h3>
<CodeHighlight lang="javascript"> <CodeHighlight lang="javascript">
import {Paginator} from 'primereact/paginator'; import Paginator from 'primevue/paginator';
</CodeHighlight> </CodeHighlight>
<h3>Getting Started</h3> <h3>Getting Started</h3>
<p><i>rows</i> and <i>totalRecords</i> define how many pages the paginator should display. Paginator below has 10 pages.</p> <p><i>rows</i> and <i>totalRecords</i> define how many pages the paginator should display. Paginator below has 10 pages.</p>
<CodeHighlight> <CodeHighlight>
&lt;Paginator :rows="10" :totalRecords="100"&gt;&lt;/Paginator&gt; &lt;Paginator :rows="10" :totalRecords="totalItems"&gt;&lt;/Paginator&gt;
</CodeHighlight> </CodeHighlight>
<h3>Rows Per Page</h3> <h3>Start Offset</h3>
<p>Number of items per page can be changed by the user using a dropdown if you define rowsPerPageOptions as an array of possible values. In this case, <p><i>first</i> property defines the index of the first item displayed by the paginator. This is useful in cases where the paginator needs to be controlled programmatically such as resetting or navigating to a certain page.</p>
rows property should also be updated <CodeHighlight>
</p> &lt;Paginator :first="offset" :rows="10" :totalRecords="totalItems"&gt;&lt;/Paginator&gt;
</CodeHighlight>
<h3>Template</h3> <h3>Rows Per Page</h3>
<p>Paginator elements can be customized using the template property using the predefined keys, default value is <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>
"FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown". Here are the available elements that <CodeHighlight>
can be placed inside a paginator.</p> &lt;Paginator :first="offset" :rows="10" :totalRecords="totalItems" :rowsPerPageOptions="[10,20,30]"&gt;&lt;/Paginator&gt;
</CodeHighlight>
<ul> <h3>Template</h3>
<li>FirstPageLink</li> <p>Paginator elements can be customized using the template property using the predefined keys, default value is
<li>PrevPageLink</li> "FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown". Here are the available elements that
<li>PageLinks</li> can be placed inside a paginator in any order.</p>
<li>NextPageLink</li>
<li>LastPageLink</li>
<li>RowsPerPageDropdown</li>
<li>CurrentPageReport</li>
</ul>
<h3>Properties</h3> <ul>
<div class="doc-tablewrapper"> <li>FirstPageLink</li>
<table class="doc-table"> <li>PrevPageLink</li>
<thead> <li>PageLinks</li>
<li>NextPageLink</li>
<li>LastPageLink</li>
<li>RowsPerPageDropdown</li>
<li>CurrentPageReport</li>
</ul>
<CodeHighlight>
&lt;Paginator :first="offset" :rows="10" :totalRecords="totalItems" template="FirstPageLink PrevPageLink CurrentPageReport NextPageLink LastPageLink"&gt;&lt;/Paginator&gt;
</CodeHighlight>
<h3>Page Change Event</h3>
<p>Paginator provides only one event called <i>page-change</i> along with all the information about the change event</p>
<CodeHighlight>
&lt;Paginator :first="offset" :rows="10" :totalRecords="totalItems" @page-change="onPage($event)"&gt;&lt;/Paginator&gt;
</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.page: Index of the 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.</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-change</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.page: Index of the 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> <tr>
<th>Name</th> <th>Name</th>
<th>Type</th> <th>Element</th>
<th>Default</th>
<th>Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <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>style</td>
<td>string</td>
<td>null</td>
<td>Inline style of the element.</td>
</tr>
<tr>
<td>class</td>
<td>string</td>
<td>null</td>
<td>Style class of the element.</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>leftContent</td>
<td>any</td>
<td>null</td>
<td>Content to inject into the left side of the paginator.</td>
</tr>
<tr>
<td>rightContent</td>
<td>any</td>
<td>null</td>
<td>Content to inject into the right side 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.</td>
</tr>
</tbody>
</table>
</div>
<h3>Events</h3>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr> <tr>
<th>Name</th> <td>p-paginator</td>
<th>Parameters</th> <td>Container element.</td>
<th>Description</th>
</tr> </tr>
</thead> <tr>
<tbody> <td>p-paginator-first</td>
<tr> <td>First page element.</td>
<td>onPageChange</td> </tr>
<td>event.page: New page number <br/> <tr>
event.first: Index of first record <br/> <td>p-paginator-prev</td>
event.rows: Number of rows to display in new page <br/> <td>Previous page element.</td>
event.page: Index of the new page <br/> </tr>
event.pageCount: Total number of pages <tr>
</td> <td>p-paginator-pages</td>
<td>Callback to invoke when page changes, the event object contains information about the new state.</td> <td>Container of page links.</td>
</tr> </tr>
</tbody> <tr>
</table> <td>p-paginator-page</td>
</div> <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>Styling</h3> <h3>Dependencies</h3>
<p>Following is the list of structural style classes, for theming classes visit <router-link to="/theming">theming</router-link> page.</p> <p>None.</p>
<div class="doc-tablewrapper"> </div>
<table class="doc-table"> </TabPanel>
<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"> <TabPanel header="Source">
<a href="https://github.com/primefaces/primereact/tree/master/src/showcase/paginator" class="btn-viewsource" target="_blank" rel="noopener noreferrer"> <a href="https://github.com/primefaces/primereact/tree/master/src/showcase/paginator" class="btn-viewsource" target="_blank" rel="noopener noreferrer">