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

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>
<li>FirstPageLink</li>
<li>PrevPageLink</li>
<li>PageLinks</li>
<li>NextPageLink</li>
<li>LastPageLink</li>
<li>RowsPerPageDropdown</li>
<li>CurrentPageReport</li>
</ul>
<h3>Properties</h3> <h3>Template</h3>
<div class="doc-tablewrapper"> <p>Paginator elements can be customized using the template property using the predefined keys, default value is
<table class="doc-table"> "FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown". Here are the available elements that
<thead> 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>
<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">