Skip to content

Commit b285f88

Browse files
Merge branch 'main' of https://github.com/HC200ok/vue3-easy-data-table into feature/bodyslots
2 parents 62aa4ca + bc8ca54 commit b285f88

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "HC200ok",
44
"description": "A customizable and easy-to-use data table component made with Vue.js 3.x.",
55
"private": false,
6-
"version": "1.4.12",
6+
"version": "1.4.14",
77
"types": "./types/main.d.ts",
88
"license": "MIT",
99
"files": [

src/components/DataTable.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,13 @@ const {
384384
sortBy,
385385
sortType,
386386
updateServerOptionsSort,
387-
emits
387+
emits,
388388
);
389389
390390
const {
391391
rowsItemsComputed,
392392
rowsPerPageRef,
393+
updateRowsPerPage,
393394
} = useRows(
394395
isServerSideMode,
395396
rowsItems,
@@ -528,6 +529,9 @@ defineExpose({
528529
nextPage,
529530
prevPage,
530531
updatePage,
532+
rowsPerPageOptions: rowsItemsComputed,
533+
rowsPerPageActiveOption: rowsPerPageRef,
534+
updateRowsPerPageActiveOption: updateRowsPerPage,
531535
});
532536
</script>
533537

@@ -563,6 +567,9 @@ defineExpose({
563567
--easy-table-footer-font-size: 12px;
564568
--easy-table-footer-padding: 0px 5px;
565569
--easy-table-footer-height: 36px;
570+
/**footer-rowsPerPage**/
571+
--easy-table-rows-per-page-selector-width: auto;
572+
--easy-table-rows-per-page-selector-option-padding: 5px;
566573
/*message*/
567574
--easy-table-message-font-color: #212121;
568575
--easy-table-message-font-size: 12px;
@@ -587,4 +594,3 @@ defineExpose({
587594
height: v-bind(tableHeightPx);
588595
}
589596
</style>
590-

src/components/RowsSelector.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const themeColor = inject('themeColor');
103103
min-width: 45px;
104104
position: relative;
105105
margin: 0px 10px;
106+
width: var(--easy-table-rows-per-page-selector-width);
106107
.rows-input__wrapper {
107108
height: 20px;
108109
border-bottom: 1px solid var(--easy-table-footer-font-color);
@@ -141,7 +142,7 @@ const themeColor = inject('themeColor');
141142
box-shadow: 0 5px 5px -3px rgb(0 0 0 / 20%), 0 8px 10px 1px rgb(0 0 0 / 14%), 0 3px 14px 2px rgb(0 0 0 / 12%);
142143
li {
143144
cursor: pointer;
144-
padding: 5px;
145+
padding: var(--easy-table-rows-per-page-selector-option-padding);
145146
background-color: var(--easy-table-footer-background-color);
146147
147148
&.selected {

src/hooks/useRows.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ export default function useRows(
1616

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

19+
const updateRowsPerPage = (option: number) => {
20+
rowsPerPageRef.value = option;
21+
};
22+
1923
return {
2024
rowsItemsComputed,
2125
rowsPerPageRef,
26+
updateRowsPerPage,
2227
};
2328
}

src/modes/Client.vue

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
:body-item-class-name="bodyItemClassNameFunction"
3434
@click-row="showItem"
3535
@update-sort="updateSort"
36+
hide-footer
3637
>
3738
<template #body.prepend="body">
3839
<tr>
@@ -75,6 +76,21 @@
7576
</DataTable>
7677

7778
<div class="customize-footer">
79+
<div class="customize-rows-per-page">
80+
<select
81+
class="select-items"
82+
@change="updateRowsPerPageSelect"
83+
>
84+
<option
85+
v-for="item in rowsPerPageOptions"
86+
:key="item"
87+
:selected="item === rowsPerPageActiveOption"
88+
:value="item"
89+
>
90+
{{ item }} rows per page
91+
</option>
92+
</select>
93+
</div>
7894
<div class="customize-index">
7995
Now displaying: {{ currentPageFirstIndex }} ~ {{ currentPageLastIndex }} of {{ totalItemsLength }}
8096
</div>
@@ -112,12 +128,15 @@
112128
import {
113129
computed, ref, reactive, toRefs,
114130
} from 'vue';
131+
// import { useRowsPerPage } from 'use-vue3-easy-data-table';
132+
// import type { UseRowsPerPageReturn } from 'use-vue3-easy-data-table';
115133
import type {
116134
Header, Item, FilterOption, ClickRowArgument, UpdateSortArgument, HeaderItemClassNameFunction, BodyItemClassNameFunction, BodyRowClassNameFunction,
117135
} from '../types/main';
118136
import DataTable from '../components/DataTable.vue';
119137
import { mockClientNestedItems, mockClientItems, mockDuplicateClientNestedItems } from '../mock';
120138
139+
121140
const searchField = ref('name');
122141
const searchValue = ref('');
123142
@@ -205,6 +224,7 @@ const dataTable = ref();
205224
// index related
206225
const currentPageFirstIndex = computed(() => dataTable.value?.currentPageFirstIndex);
207226
const currentPageLastIndex = computed(() => dataTable.value?.currentPageLastIndex);
227+
208228
const totalItemsLength = computed(() => dataTable.value?.totalItemsLength);
209229
210230
// paginations related
@@ -226,6 +246,24 @@ const updatePage = (paginationNumber: number) => {
226246
const isDataHeader = (header: Header) => {
227247
return !(header.value === 'checkbox' || header.value === 'index' || header.value === 'expand')
228248
}
249+
250+
// rows per page
251+
const rowsPerPageOptions = computed(() => dataTable.value?.rowsPerPageOptions);
252+
const rowsPerPageActiveOption = computed(() => dataTable.value?.rowsPerPageActiveOption);
253+
254+
const updateRowsPerPageSelect = (e: Event) => {
255+
dataTable.value.updateRowsPerPageActiveOption(Number((e.target as HTMLInputElement).value));
256+
};
257+
258+
// const {
259+
// rowsPerPageOptions,
260+
// rowsPerPageActiveOption,
261+
// updateRowsPerPageActiveOption,
262+
// }: UseRowsPerPageReturn = useRowsPerPage(dataTable);
263+
264+
// const updateRowsPerPageSelect = (e: Event) => {
265+
// updateRowsPerPageActiveOption(Number((e.target as HTMLInputElement).value));
266+
// };
229267
</script>
230268

231269
<style scoped>
@@ -296,6 +334,9 @@ const isDataHeader = (header: Header) => {
296334
--easy-table-footer-padding: 0px 10px;
297335
--easy-table-footer-height: 40px;
298336
337+
--easy-table-rows-per-page-selector-width: 70px;
338+
--easy-table-rows-per-page-selector-option-padding: 10px;
339+
299340
--easy-table-scrollbar-track-color: #4c5d7a;
300341
--easy-table-scrollbar-color: #4c5d7a;
301342
--easy-table-scrollbar-corner-color: #4c5d7a;

0 commit comments

Comments
 (0)