Skip to content

Commit

Permalink
Merge pull request #2 from Sreesanth46/feature/pagination
Browse files Browse the repository at this point in the history
Feature/pagination
  • Loading branch information
Sreesanth46 authored Nov 5, 2023
2 parents 6825843 + df78474 commit 312172f
Show file tree
Hide file tree
Showing 14 changed files with 1,332 additions and 101 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: ci

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: node
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org
- run: npm install
- run: npm build
- name: publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
93 changes: 90 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# VueTable
# VueTable + VuePaginator

This is a Table component for Vue.js

Expand Down Expand Up @@ -83,11 +83,98 @@ const data = [{
<template>
```

### Props
### Props - VueTable

| Prop | Description | Default |
| --------- | -------------------------------------- | ------- |
| `data` | Data to be rendered | `[]` |
| `headers` | heading of the table | `[]` |
| `headers` | Heading of the table | `[]` |
| `keys` | Keys of the table data (can be nested) | `[]` |
| `dark` | Dark mode | `false` |

## VuePaginator

![VueTable Pagination demo](paginationdemo.gif)

```js

<script setup>
import { VueTable, VuePaginator } from '@harv46/vue-table';
import '@harv46/vue-table/dist/style.css';
import data from '@/assets/data.json';
import { computed, ref, watch } from 'vue';

const headers = [
'id',
'name',
'DOB',
'GPA',
'course',
'department',
'fees paid'
];
const keyValues = [
'id',
'name',
'date_of_birth',
'GPA',
'course',
'department',
'fees_paid'
];

const itemsPerPage = 8;

const startOffSet = ref(0);
const endOffSet = ref(startOffSet.value + itemsPerPage);

watch(startOffSet, nOff => {
endOffSet.value = startOffSet.value + itemsPerPage;
});

const pageCount = Math.ceil(data.length / itemsPerPage);

const currentData = computed(() =>
data.slice(startOffSet.value, endOffSet.value)
);

function onPageChange(pageNumber) {
const newOffSet = (pageNumber - 1) * itemsPerPage;
startOffSet.value = newOffSet;
}
</script>

<template>
<div
style="
width: 90%;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
margin-top: 6%;
">
<VueTable :headers="headers" :keys="keyValues" :data="currentData" />
<div
style="
display: flex;
flex-direction: column;
align-items: center;
margin-top: 2rem;
">
<VuePaginator :pageCount="pageCount" @onPageChange="onPageChange" />
</div>
</div>
</template>

```

### Props - VuePaginator

| Prop | Description | Default |
| ------------- | ------------------------------------------------------------------------------------------- | ------- |
| `large` | Change the size of the paginator | `false` |
| `dark` | Dark mode | `false` |
| `defaultPage` | Default selected page | `1` |
| `bufferCount` | Specify the number of adjacent pages displayed on both sides of the currently selected page | `2` |
| `pageCount` | Number of pages to be displayed | `5` |
79 changes: 60 additions & 19 deletions demo/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
<script setup>
import { VueTable } from "../../dist/es.js";
import "../../dist/style.css";
const headers = ["name", "age"];
const keyValues = ["name", "age"];
const datas = [
{ name: "example 1", age: 19 },
{ name: "example 2", age: 22 },
{ name: "example 3", age: 40 },
import { VueTable, VuePaginator } from '../../dist/es.js';
import '../../dist/style.css';
import data from './assets/data.json';
import { computed, ref, watch } from 'vue';
const headers = [
'id',
'name',
'DOB',
'GPA',
'course',
'department',
'fees paid'
];
const keyValues = [
'id',
'name',
'date_of_birth',
'GPA',
'course',
'department',
'fees_paid'
];
const itemsPerPage = 8;
const startOffSet = ref(0);
const endOffSet = ref(startOffSet.value + itemsPerPage);
watch(startOffSet, nOff => {
endOffSet.value = startOffSet.value + itemsPerPage;
});
const pageCount = Math.ceil(data.length / itemsPerPage);
const currentData = computed(() =>
data.slice(startOffSet.value, endOffSet.value)
);
function onPageChange(pageNumber) {
const newOffSet = (pageNumber - 1) * itemsPerPage;
startOffSet.value = newOffSet;
}
</script>

<template>
<div
style="
width: 90%;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
margin-top: 6%;
">
<VueTable :headers="headers" :keys="keyValues" :data="currentData" />
<div
style="
width: 90%;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
margin-top: 6%;
"
>
<VueTable :headers="headers" :keys="keyValues" :data="datas" />
style="
display: flex;
flex-direction: column;
align-items: center;
margin-top: 2rem;
">
<VuePaginator :pageCount="pageCount" @onPageChange="onPageChange" />
</div>
</div>
</template>
Loading

0 comments on commit 312172f

Please sign in to comment.