Skip to content

Commit

Permalink
adding page navigation mode to pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
xaksis committed Jul 18, 2018
1 parent 5ae7289 commit 36d7f37
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 9 deletions.
8 changes: 6 additions & 2 deletions dev/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
@on-sort-change="onSortChange"
:columns="columns"
:rows="rows"
theme="black-rhino"
theme="nocturnal"
:line-numbers="true"
:pagination-options="{ enabled: true, perPage: 5}"
:pagination-options="{
enabled: true,
perPage: 5,
mode: 'pages',
}"
:select-options="{
enabled: true,
selectOnCheckboxOnly: false,
Expand Down
18 changes: 18 additions & 0 deletions src/components/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
:perPage="perPage"
:rtl="rtl"
:total="totalRows || totalRowCount"
:mode="paginationMode"
:nextText="nextText"
:prevText="prevText"
:rowsPerPageText="rowsPerPageText"
:customRowsPerPageDropdown="customRowsPerPageDropdown"
:paginateDropdownAllowAll="paginateDropdownAllowAll"
:ofText="ofText"
:pageText="pageText"
:allText="allText"></vgt-pagination>
</slot>
<vgt-global-search
Expand Down Expand Up @@ -206,12 +208,14 @@
:perPage="perPage"
:rtl="rtl"
:total="totalRows || totalRowCount"
:mode="paginationMode"
:nextText="nextText"
:prevText="prevText"
:rowsPerPageText="rowsPerPageText"
:customRowsPerPageDropdown="customRowsPerPageDropdown"
:paginateDropdownAllowAll="paginateDropdownAllowAll"
:ofText="ofText"
:pageText="pageText"
:allText="allText"
></vgt-pagination>
</slot>
Expand Down Expand Up @@ -294,6 +298,7 @@ export default {
perPageDropdown: null,
position: 'bottom',
dropdownAllowAll: true,
mode: 'records', // or pages
};
},
},
Expand Down Expand Up @@ -321,6 +326,7 @@ export default {
rowsPerPageText: 'Rows per page',
ofText: 'of',
allText: 'All',
pageText: 'page',
// internal select options
selectable: false,
Expand Down Expand Up @@ -348,6 +354,7 @@ export default {
paginateOnBottom: true,
customRowsPerPageDropdown: [],
paginateDropdownAllowAll: true,
paginationMode: 'records',
currentPage: 1,
currentPerPage: 10,
Expand Down Expand Up @@ -1159,8 +1166,10 @@ export default {
prevLabel,
rowsPerPageLabel,
ofLabel,
pageLabel,
allLabel,
setCurrentPage,
mode,
} = this.paginationOptions;
if (typeof enabled === 'boolean') {
Expand All @@ -1187,6 +1196,10 @@ export default {
this.paginateDropdownAllowAll = dropdownAllowAll;
}
if (typeof mode === 'string') {
this.paginationMode = mode;
}
if (typeof nextLabel === 'string') {
this.nextText = nextLabel;
}
Expand All @@ -1202,11 +1215,16 @@ export default {
if (typeof ofLabel === 'string') {
this.ofText = ofLabel;
}
if (typeof pageLabel === 'string') {
this.pageText = pageLabel;
}
if (typeof allLabel === 'string') {
this.allText = allLabel;
}
if (typeof setCurrentPage === 'number') {
setTimeout(() => {
this.changePage(setCurrentPage);
Expand Down
20 changes: 18 additions & 2 deletions src/components/VgtPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@
<span class="chevron" v-bind:class="{ 'left': !rtl, 'right': rtl }"></span>
<span>{{prevText}}</span>
</a>
<div class="footer__navigation__info">{{paginatedInfo}}</div>
<pagination-page-info
@page-changed="changePage"
:totalRecords="total"
:currentPerPage="currentPerPage"
:currentPage="currentPage"
:ofText="ofText"
:pageText="pageText"
v-if="mode === 'pages'">
</pagination-page-info>
<div v-else class="footer__navigation__info">{{paginatedInfo}}</div>
<a href="javascript:undefined" class="footer__navigation__page-btn"
:class="{ disabled: !nextIsPossible }" @click.prevent.stop="nextPage" tabindex="0">
<span>{{nextText}}</span>
Expand All @@ -39,6 +48,7 @@

<script>
import cloneDeep from 'lodash.clonedeep';
import VgtPaginationPageInfo from './VgtPaginationPageInfo';
export default {
name: 'VgtPagination',
Expand All @@ -49,12 +59,14 @@ export default {
rtl: { default: false },
customRowsPerPageDropdown: { default() { return []; } },
paginateDropdownAllowAll: { default: true },
mode: { default: 'records' },
// text options
nextText: { default: 'Next' },
prevText: { default: 'Prev' },
rowsPerPageText: { default: 'Rows per page:' },
ofText: { default: 'of' },
pageText: { default: 'page' },
allText: { default: 'All' },
},
Expand Down Expand Up @@ -121,7 +133,7 @@ export default {
},
changePage(pageNumber) {
if (pageNumber > 0 && this.total > this.currentPerPage * pageNumber) {
if (pageNumber > 0 && this.total > this.currentPerPage * (pageNumber - 1)) {
this.currentPage = pageNumber;
this.pageChanged();
}
Expand Down Expand Up @@ -185,6 +197,10 @@ export default {
mounted() {
this.handlePerPage();
},
components: {
'pagination-page-info': VgtPaginationPageInfo,
},
};
</script>

Expand Down
71 changes: 71 additions & 0 deletions src/components/VgtPaginationPageInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<template>
<div class="footer__navigation__page-info">
{{pageText}} <input
class="footer__navigation__page-info__current-entry"
type="text"
@keyup.enter.stop="changePage"
:value="currentPage"> {{pageInfo}}
</div>
</template>

<script>
export default {
name: 'VgtPaginationPageInfo',
props: {
currentPerPage: {
default: 10,
},
currentPage: {
default: 1,
},
totalRecords: {
default: 0,
},
ofText: {
default: 'of',
type: String,
},
pageText: {
default: 'page',
type: String,
},
},
data() {
return {
};
},
computed: {
pageInfo() {
return `${this.ofText} ${this.lastPage}`;
},
lastPage() {
return Math.ceil(this.totalRecords / this.currentPerPage);
},
},
methods: {
changePage(event) {
const value = parseInt(event.target.value, 10);
//! invalid number
if (Number.isNaN(value)
|| value > this.lastPage
|| value < 1) {
event.target.value = this.currentPage;
return false;
}
//* valid number
event.target.value = value;
this.$emit('page-changed', value);
},
},
mounted() {
},
components: {
},
};
</script>

<style lang="scss" scoped>
</style>
14 changes: 12 additions & 2 deletions src/styles/_table-footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
.footer__navigation{
font-size: 14px;
&__page-btn, &__info{
&__page-btn, &__info, &__page-info{
display: inline-block;
vertical-align: middle;
}
Expand Down Expand Up @@ -82,10 +82,20 @@
}
}
}
&__info{
&__info, &__page-info{
display: inline-block;
color: $secondary-text-color;
margin: 0px 16px;
}
&__page-info{
&__current-entry{
width: 30px;
text-align: center;
display: inline-block;
margin: 0px 10px;
font-weight: bold;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/styles/black-rhino/black-rhino.scss
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
}
}
}
&__info{
&__info, &__page-info{
color: $text-color;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/styles/nocturnal/nocturnal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

//th
& th.line-numbers {
& th.line-numbers, & th.vgt-checkbox-col {
color: $text-color;
border-right: 1px solid $border-color;
background: linear-gradient($thead-bg-color-1, $thead-bg-color-2);
Expand Down Expand Up @@ -77,7 +77,7 @@
}
}
}
&__info{
&__info, &__page-info{
color: $secondary-text-color;
}
}
Expand Down
76 changes: 76 additions & 0 deletions vp-docs/.vuepress/components/pagination-table.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<template>
<div>
<vue-good-table
:columns="columns"
:rows="rows"
:pagination-options="options">
</vue-good-table>
</div>
</template>

<script>
export default {
name: 'pagination-table',
props: ['options'],
data() {
return {
columns: [
{
label: 'Name',
field: 'name',
},
{
label: 'Age',
field: 'age',
type: 'number',
},
{
label: 'Created On',
field: 'createdAt',
type: 'date',
dateInputFormat: 'YYYY-MM-DD',
dateOutputFormat: 'MMM Do YY',
},
{
label: 'Percent',
field: 'score',
type: 'percentage',
},
],
rows: [
{ id:1, name:"John", age: 20, createdAt: '201-10-31:9: 35 am',score: 0.03343 },
{ id:2, name:"Jane", age: 24, createdAt: '2011-10-31', score: 0.03343 },
{ id:3, name:"Susan", age: 16, createdAt: '2011-10-30', score: 0.03343 },
{ id:4, name:"Chris", age: 55, createdAt: '2011-10-11', score: 0.03343 },
{ id:5, name:"Dan", age: 40, createdAt: '2011-10-21', score: 0.03343 },
{ id:6, name:"John", age: 20, createdAt: '2011-10-31', score: 0.03343 },
],
};
},
computed: {
},
methods: {
},
mounted () {
},
components: {
},
};
</script>

<style>
table{
display: table;
margin: 0;
}
tr {
border-top: none;
}
tr:nth-child(2n) {
background-color: transparent;
}
th, td {
border: none;
padding: auto auto;
}
</style>
Loading

0 comments on commit 36d7f37

Please sign in to comment.