Skip to content

Commit 5487b70

Browse files
committed
add headerTextDirection & bodyTextDirection
1 parent bc8ca54 commit 5487b70

File tree

7 files changed

+81
-11
lines changed

7 files changed

+81
-11
lines changed

src/components/DataTable.vue

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<span
5454
v-else
5555
class="header"
56+
:class="`direction-${headerTextDirection}`"
5657
>
5758
<slot
5859
v-if="slots[`header-${header.value}`]"
@@ -80,6 +81,21 @@
8081
class="vue3-easy-data-table__body"
8182
:class="{'row-alternation': alternating}"
8283
>
84+
<slot
85+
name="body-prepend"
86+
v-bind="{
87+
items: pageItems,
88+
pagination: {
89+
isFirstPage,
90+
isLastPage,
91+
currentPaginationNumber,
92+
maxPaginationNumber,
93+
nextPage,
94+
prevPage
95+
},
96+
headers: headersForRender
97+
}"
98+
/>
8399
<template
84100
v-for="(item, index) in pageItems"
85101
:key="index"
@@ -96,7 +112,8 @@
96112
:class="[{
97113
'shadow': column === lastFixedColumn,
98114
'can-expand': column === 'expand',
99-
}, typeof bodyItemClassName === 'string' ? bodyItemClassName : bodyItemClassName(column, i)]"
115+
// eslint-disable-next-line max-len
116+
}, typeof bodyItemClassName === 'string' ? bodyItemClassName : bodyItemClassName(column, i), `direction-${bodyTextDirection}`]"
100117
@click="column === 'expand' ? updateExpandingItemIndexList(index, item, $event) : null"
101118
>
102119
<slot
@@ -140,6 +157,21 @@
140157
</td>
141158
</tr>
142159
</template>
160+
<slot
161+
name="body-append"
162+
v-bind="{
163+
items: pageItems,
164+
pagination: {
165+
isFirstPage,
166+
isLastPage,
167+
currentPaginationNumber,
168+
maxPaginationNumber,
169+
nextPage,
170+
prevPage
171+
},
172+
headers: headersForRender
173+
}"
174+
/>
143175
</tbody>
144176
</table>
145177
<div
@@ -260,6 +292,7 @@ const props = defineProps({
260292
});
261293
262294
const {
295+
bodyTextDirection,
263296
checkboxColumnWidth,
264297
expandColumnWidth,
265298
filterOptions,
@@ -268,6 +301,7 @@ const {
268301
fixedHeader,
269302
fixedIndex,
270303
headers,
304+
headerTextDirection,
271305
indexColumnWidth,
272306
items,
273307
itemsSelected,

src/modes/Client.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
@click-row="showItem"
3535
@update-sort="updateSort"
3636
hide-footer
37+
body-text-direction="left"
38+
header-text-direction="left"
3739
>
38-
3940
<template #expand="item">
4041
<div style="padding: 15px">
4142
{{ item.name }} won championships
@@ -118,11 +119,11 @@ import {
118119
// import type { UseRowsPerPageReturn } from 'use-vue3-easy-data-table';
119120
import type {
120121
Header, Item, FilterOption, ClickRowArgument, UpdateSortArgument, HeaderItemClassNameFunction, BodyItemClassNameFunction, BodyRowClassNameFunction,
122+
TextDirection,
121123
} from '../types/main';
122124
import DataTable from '../components/DataTable.vue';
123125
import { mockClientNestedItems, mockClientItems, mockDuplicateClientNestedItems } from '../mock';
124126
125-
126127
const searchField = ref('name');
127128
const searchValue = ref('');
128129
@@ -139,15 +140,15 @@ const switchToNested = () => {
139140
const headers: Header[] = [
140141
{ text: 'Name', value: 'name' },
141142
{
142-
text: 'Address', value: 'address', width: 200, fixed: true,
143+
text: 'Address', value: 'address', fixed: true,
143144
},
144145
{ text: 'Height', value: 'info.out.height', sortable: true },
145146
{ text: 'Weight', value: 'info.out.weight', sortable: true },
146147
{
147-
text: 'Age', value: 'age', sortable: true, width: 200,
148+
text: 'Age', value: 'age', sortable: true
148149
},
149-
{ text: 'Favourite sport', value: 'favouriteSport', width: 200 },
150-
{ text: 'Favourite fruits', value: 'favouriteFruits', width: 200 },
150+
{ text: 'Favourite sport', value: 'favouriteSport' },
151+
{ text: 'Favourite fruits', value: 'favouriteFruits' },
151152
];
152153
153154
// const headers: Header[] = [
@@ -296,7 +297,7 @@ const updateRowsPerPageSelect = (e: Event) => {
296297
--easy-table-header-font-color: #c1cad4;
297298
--easy-table-header-background-color: #2d3a4f;
298299
299-
--easy-table-header-item-padding: 10px 15px;
300+
/* --easy-table-header-item-padding: 10px 15px; */
300301
301302
--easy-table-body-even-row-font-color: #fff;
302303
--easy-table-body-even-row-background-color: #4c5d7a;
@@ -309,7 +310,7 @@ const updateRowsPerPageSelect = (e: Event) => {
309310
--easy-table-body-row-hover-font-color: #2d3a4f;
310311
--easy-table-body-row-hover-background-color: #eee;
311312
312-
--easy-table-body-item-padding: 10px 15px;
313+
/* --easy-table-body-item-padding: 10px 15px; */
313314
314315
--easy-table-footer-background-color: #2d3a4f;
315316
--easy-table-footer-font-color: #c0c7d2;

src/propsWithDefault.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PropType } from 'vue';
22
import type {
33
SortType, Item, ServerOptions, FilterOption,
44
HeaderItemClassNameFunction, BodyItemClassNameFunction, BodyRowClassNameFunction,
5+
TextDirection,
56
} from './types/main';
67

78
export default {
@@ -45,6 +46,14 @@ export default {
4546
type: Boolean,
4647
default: false,
4748
},
49+
headerTextDirection: {
50+
type: String as PropType<TextDirection>,
51+
default: 'left',
52+
},
53+
bodyTextDirection: {
54+
type: String as PropType<TextDirection>,
55+
default: 'left',
56+
},
4857
hideFooter: {
4958
type: Boolean,
5059
default: false,
@@ -149,4 +158,4 @@ export default {
149158
type: Boolean,
150159
default: false,
151160
},
152-
}
161+
};

src/scss/checbox.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ $line-color: #fff;
1717
position: relative;
1818
width: $checkbox-size;
1919
height: $checkbox-size;
20-
20+
font-size: var(--easy-table-body-row-font-size);
21+
margin: 0 auto;
2122
label {
2223
cursor: pointer;
2324
display: inline;

src/scss/vue3-easy-data-table.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ table {
118118
.header {
119119
display: flex;
120120
align-items: center;
121+
&.direction-left {
122+
justify-content: flex-start;
123+
}
124+
&.direction-center {
125+
justify-content: center;
126+
}
127+
&.direction-right {
128+
justify-content: flex-end;
129+
}
121130
}
122131

123132
&.sortable {
@@ -198,6 +207,18 @@ table {
198207
border: none;
199208
border-bottom: var(--easy-table-row-border);
200209

210+
&.direction-left {
211+
text-align: left;
212+
}
213+
214+
&.direction-center {
215+
text-align: center;
216+
}
217+
218+
&.direction-right {
219+
text-align: right;
220+
}
221+
201222
position: relative;
202223
.expand-icon {
203224
border: solid;

src/types/main.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ export type UpdateSortArgument = {
5050
export type HeaderItemClassNameFunction = (header: Header, index: number) => string
5151
export type BodyRowClassNameFunction = (item: Item, index: number) => string
5252
export type BodyItemClassNameFunction = (column: string, index: number) => string
53+
54+
export type TextDirection = 'center' | 'left' | 'right'

types/main.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ export type UpdateSortArgument = {
5050
export type HeaderItemClassNameFunction = (header: Header, index: number) => string
5151
export type BodyRowClassNameFunction = (item: Item, index: number) => string
5252
export type BodyItemClassNameFunction = (column: string, index: number) => string
53+
54+
export type TextDirection = 'center' | 'left' | 'right'

0 commit comments

Comments
 (0)