Skip to content

Commit 249f979

Browse files
authored
Merge pull request #63 from HC200ok/feature/expand-row-slot
async data for expand row
2 parents dfb41fd + 6bbf8d9 commit 249f979

File tree

4 files changed

+84
-5
lines changed

4 files changed

+84
-5
lines changed

package.json

+1-1
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.3.3",
6+
"version": "1.3.4",
77
"types": "./types/main.d.ts",
88
"license": "MIT",
99
"files": [

src/components/DataTable.vue

+22-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
'no-padding': noTdPadding,
9595
'can-expand': column === 'expand',
9696
}"
97-
@click="column === 'expand' ? updateExpandingItemIndexList(index, $event) : null"
97+
@click="column === 'expand' ? updateExpandingItemIndexList(index, item, $event) : null"
9898
>
9999
<slot
100100
v-if="slots[`item-${column}`]"
@@ -124,7 +124,12 @@
124124
>
125125
<td
126126
:colspan="headersForRender.length"
127+
class="expand"
127128
>
129+
<LoadingLine
130+
v-if="item.expandLoading"
131+
class="expand-loading"
132+
/>
128133
<slot
129134
name="expand"
130135
v-bind="item"
@@ -221,6 +226,7 @@ import MutipleSelectCheckBox from './MutipleSelectCheckBox.vue';
221226
import SingleSelectCheckBox from './SingleSelectCheckBox.vue';
222227
import RowsSelector from './RowsSelector.vue';
223228
import Loading from './Loading.vue';
229+
import LoadingLine from './LoadingLine.vue';
224230
import ButtonsPagination from './ButtonsPagination.vue';
225231
import PaginationArrows from './PaginationArrows.vue';
226232
@@ -438,6 +444,10 @@ const props = defineProps({
438444
type: String,
439445
default: 'rows per page:',
440446
},
447+
expandLoading: {
448+
type: Boolean,
449+
default: false,
450+
},
441451
});
442452
443453
const {
@@ -503,6 +513,7 @@ const emits = defineEmits([
503513
'update:itemsSelected',
504514
'update:serverOptions',
505515
'clickRow',
516+
'expandRow',
506517
]);
507518
508519
const serverOptionsComputed = computed({
@@ -615,12 +626,13 @@ const headersForRender = computed((): HeaderForRender[] => {
615626
616627
// expand
617628
const expandingItemIndexList = ref<number[]>([]);
618-
const updateExpandingItemIndexList = (expandingItemIndex: number, event: Event) => {
629+
const updateExpandingItemIndexList = (expandingItemIndex: number, expandingItem: Item, event: Event) => {
619630
event.stopPropagation();
620631
const index = expandingItemIndexList.value.indexOf(expandingItemIndex);
621632
if (index !== -1) {
622633
expandingItemIndexList.value.splice(index, 1);
623634
} else {
635+
emits('expandRow', props.items.findIndex((item) => item === expandingItem));
624636
expandingItemIndexList.value.push(expandingItemIndex);
625637
}
626638
};
@@ -1205,6 +1217,14 @@ defineExpose({
12051217
border: none;
12061218
border-bottom: 1px solid v-bind(rowBorderColor);
12071219
position: relative;
1220+
&.expand {
1221+
position: relative;
1222+
.expand-loading {
1223+
position: absolute;
1224+
top: 0px;
1225+
left: 0px;
1226+
}
1227+
}
12081228
&.can-expand {
12091229
cursor: pointer;
12101230
}

src/components/LoadingLine.vue

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<template>
2+
<div class="loader-line"></div>
3+
</template>
4+
5+
<script lang="ts" setup>
6+
import { inject } from 'vue';
7+
8+
const themeColor = inject('themeColor');
9+
</script>
10+
11+
<style lang="scss" scoped>
12+
.loader-line {
13+
width: 100%;
14+
height: 3px;
15+
position: relative;
16+
overflow: hidden;
17+
background-color: #ddd;
18+
margin: 0x auto;
19+
}
20+
21+
.loader-line:before {
22+
content: "";
23+
position: absolute;
24+
left: -50%;
25+
height: 3px;
26+
width: 40%;
27+
background-color: v-bind(themeColor);
28+
-webkit-animation: lineAnim 1s linear infinite;
29+
-moz-animation: lineAnim 1s linear infinite;
30+
animation: lineAnim 1s linear infinite;
31+
}
32+
33+
@keyframes lineAnim {
34+
0% {
35+
left: -40%;
36+
}
37+
50% {
38+
left: 20%;
39+
width: 80%;
40+
}
41+
100% {
42+
left: 100%;
43+
width: 100%;
44+
}
45+
}
46+
</style>

src/mock.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable max-len */
12
import { Item, ServerOptions, Header } from './types/main';
23

34
export const headersMocked: Header[] = [
@@ -41,7 +42,7 @@ export const mockClientNestedItems = (itemsNumber = 100): Item[] => {
4142
mockItems.push({
4243
name: `name-${i}`,
4344
address: `address-${i}`,
44-
info: {out: { height: i, weight: i }},
45+
info: { out: { height: i, weight: i } },
4546
age: i,
4647
favouriteSport: sports[i % 4],
4748
favouriteFruits: fruits[i % 4],
@@ -59,7 +60,7 @@ export const mockDuplicateClientNestedItems = (itemsNumber = 100): Item[] => {
5960
mockItems.push({
6061
name: `name-${i}`,
6162
address: `address-${i}`,
62-
info: {out: { height: i, weight: i }},
63+
info: { out: { height: i, weight: i } },
6364
age: i,
6465
favouriteSport: sports[i % 4],
6566
favouriteFruits: fruits[i % 4],
@@ -77,6 +78,18 @@ export const mockDuplicateClientNestedItems = (itemsNumber = 100): Item[] => {
7778
return mockItems;
7879
};
7980

81+
export const mockItemIntroduction = async (name: string): Promise<string> => {
82+
// eslint-disable-next-line no-promise-executor-return
83+
await new Promise((s) => setTimeout(s, 2000));
84+
const briefs: Record<string, string> = {
85+
'Stephen Curry': 'Wardell Stephen Curry II is an American professional basketball player for the Golden State Warriors of the National Basketball Association (NBA).',
86+
'Lebron James': 'LeBron Raymone James Sr is an American professional basketball player for the Los Angeles Lakers of the National Basketball Association (NBA).',
87+
'Kevin Durant': 'Kevin Wayne Durant also known by his initials KD, is an American professional basketball player for the Brooklyn Nets of the National Basketball Association (NBA).',
88+
'Giannis Antetokounmpo': 'Giannis Sina Ugo Antetokounmpo (né Adetokunbo; December 6, 1994) is a Greek-Nigerian professional basketball player for the Milwaukee Bucks of the National Basketball Association (NBA).',
89+
};
90+
return briefs[name];
91+
};
92+
8093
export const mockServerItems = async (
8194
serverOptions: ServerOptions,
8295
serverItemsLength = 500,

0 commit comments

Comments
 (0)