Skip to content

Commit

Permalink
Merge pull request #96 from HC200ok/customize-rowsPerPage
Browse files Browse the repository at this point in the history
Customize rows per page
  • Loading branch information
HC200ok authored Aug 13, 2022
2 parents 3b55060 + e236a92 commit bc8ca54
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "HC200ok",
"description": "A customizable and easy-to-use data table component made with Vue.js 3.x.",
"private": false,
"version": "1.4.13",
"version": "1.4.14",
"types": "./types/main.d.ts",
"license": "MIT",
"files": [
Expand Down
4 changes: 4 additions & 0 deletions src/components/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ const {
const {
rowsItemsComputed,
rowsPerPageRef,
updateRowsPerPage,
} = useRows(
isServerSideMode,
rowsItems,
Expand Down Expand Up @@ -498,6 +499,9 @@ defineExpose({
nextPage,
prevPage,
updatePage,
rowsPerPageOptions: rowsItemsComputed,
rowsPerPageActiveOption: rowsPerPageRef,
updateRowsPerPageActiveOption: updateRowsPerPage,
});
</script>

Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ export default function useRows(

const rowsPerPageRef = ref(serverOptions.value ? serverOptions.value.rowsPerPage : rowsPerPage.value);

const updateRowsPerPage = (option: number) => {
rowsPerPageRef.value = option;
};

return {
rowsItemsComputed,
rowsPerPageRef,
updateRowsPerPage,
};
}
38 changes: 38 additions & 0 deletions src/modes/Client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
:body-item-class-name="bodyItemClassNameFunction"
@click-row="showItem"
@update-sort="updateSort"
hide-footer
>

<template #expand="item">
Expand Down Expand Up @@ -61,6 +62,21 @@
</DataTable>

<div class="customize-footer">
<div class="customize-rows-per-page">
<select
class="select-items"
@change="updateRowsPerPageSelect"
>
<option
v-for="item in rowsPerPageOptions"
:key="item"
:selected="item === rowsPerPageActiveOption"
:value="item"
>
{{ item }} rows per page
</option>
</select>
</div>
<div class="customize-index">
Now displaying: {{ currentPageFirstIndex }} ~ {{ currentPageLastIndex }} of {{ totalItemsLength }}
</div>
Expand Down Expand Up @@ -98,12 +114,15 @@
import {
computed, ref, reactive, toRefs,
} from 'vue';
// import { useRowsPerPage } from 'use-vue3-easy-data-table';
// import type { UseRowsPerPageReturn } from 'use-vue3-easy-data-table';
import type {
Header, Item, FilterOption, ClickRowArgument, UpdateSortArgument, HeaderItemClassNameFunction, BodyItemClassNameFunction, BodyRowClassNameFunction,
} from '../types/main';
import DataTable from '../components/DataTable.vue';
import { mockClientNestedItems, mockClientItems, mockDuplicateClientNestedItems } from '../mock';
const searchField = ref('name');
const searchValue = ref('');
Expand Down Expand Up @@ -191,6 +210,7 @@ const dataTable = ref();
// index related
const currentPageFirstIndex = computed(() => dataTable.value?.currentPageFirstIndex);
const currentPageLastIndex = computed(() => dataTable.value?.currentPageLastIndex);
const totalItemsLength = computed(() => dataTable.value?.totalItemsLength);
// paginations related
Expand All @@ -209,6 +229,24 @@ const prevPage = () => {
const updatePage = (paginationNumber: number) => {
dataTable.value.updatePage(paginationNumber);
};
// rows per page
const rowsPerPageOptions = computed(() => dataTable.value?.rowsPerPageOptions);
const rowsPerPageActiveOption = computed(() => dataTable.value?.rowsPerPageActiveOption);
const updateRowsPerPageSelect = (e: Event) => {
dataTable.value.updateRowsPerPageActiveOption(Number((e.target as HTMLInputElement).value));
};
// const {
// rowsPerPageOptions,
// rowsPerPageActiveOption,
// updateRowsPerPageActiveOption,
// }: UseRowsPerPageReturn = useRowsPerPage(dataTable);
// const updateRowsPerPageSelect = (e: Event) => {
// updateRowsPerPageActiveOption(Number((e.target as HTMLInputElement).value));
// };
</script>

<style scoped>
Expand Down

0 comments on commit bc8ca54

Please sign in to comment.