Skip to content

Commit 7927d91

Browse files
committed
feat: add collapsible column
1 parent 112466c commit 7927d91

File tree

5 files changed

+70
-14
lines changed

5 files changed

+70
-14
lines changed

src/components/Table/Table.scss

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,39 @@
4646
top: 0;
4747
user-select: none;
4848

49-
&[data-sortable] {
49+
&[data-sortable=true] {
5050
cursor: pointer;
51-
52-
&:hover {
51+
span:hover {
5352
color: #3490dc;
5453
}
5554
}
55+
56+
&[data-collapsed=true] {
57+
width: 1px;
58+
}
59+
}
60+
61+
.vdt-column-collapse {
62+
color: #000;
63+
cursor: pointer;
64+
position: relative;
65+
span {
66+
position: absolute;
67+
top: 2em;
68+
left: -1.5em;
69+
background: #fff;
70+
border: 1px solid #ccc;
71+
border-radius: 4px;
72+
padding: 4px;
73+
display: none;
74+
z-index: 50;
75+
}
76+
&:hover {
77+
color: #00f;
78+
span {
79+
display: block;
80+
}
81+
}
5682
}
5783

5884
.vdt-column-center span {
@@ -64,11 +90,11 @@
6490
.vdt-column-content {
6591
display: flex;
6692
align-items: center;
67-
justify-content: center;
93+
justify-content: space-between;
94+
gap: 5px;
6895
}
6996

7097
.vdt-empty-body {
7198
text-align: center;
7299
}
73100
}
74-

src/components/Table/Table.vue

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@
1010
:class="column.cssClass"
1111
:data-sortable="column.sortable"
1212
:data-sorting="column.sortingMode"
13+
:data-collapsed="column.collapsed"
1314
@click="$emit('sort-column', column)">
1415

16+
<div
17+
v-if="column.collapsible && column.collapsed"
18+
@click="column.collapsed = false"
19+
class="vdt-column-collapse"
20+
>
21+
[+]
22+
<span>{{column.title}}</span>
23+
</div>
24+
1525
<!-- COLUMN HEADER CONTENT -->
16-
<div class="vdt-column-content">
26+
<div v-else class="vdt-column-content">
1727
<span>{{ column.title }}</span>
1828

1929
<!-- SORTING INDEX -->
@@ -24,6 +34,14 @@
2434
<!-- SORTING ICON -->
2535
<component v-if="column.sortable"
2636
:is="sortingIconComponent" />
37+
38+
<div
39+
v-if="column.collapsible && !column.collapsed"
40+
@click="column.collapsed = true"
41+
class="vdt-column-collapse"
42+
>
43+
[-]
44+
</div>
2745
</div>
2846
</th>
2947
</tr>
@@ -45,21 +63,29 @@
4563
v-for="(column, j) in columns"
4664
:key="data._key + '_' + j"
4765
>
66+
<div v-if="column.collapsible && column.collapsed"></div>
4867
<component
49-
:is="column.component"
68+
v-else
5069
v-bind="{ data, ...column.componentProps }"
70+
:is="column.component"
5171
@userEvent="emitUserEvent"
5272
/>
5373
</td>
5474
</tr>
5575
</tbody>
5676

5777
<!-- COMPONENT IF LOADING -->
58-
<component v-if="isLoading" :is="loadingComponent" />
78+
<component
79+
v-if="isLoading"
80+
:is="loadingComponent"
81+
/>
5982

6083
<!-- TABLE FOOTER -->
61-
<component v-if="footerComponent" :is="footerComponent"
62-
v-bind="{ data, dataDisplayed, dataFiltered }" />
84+
<component
85+
v-if="footerComponent"
86+
v-bind="{ data, dataDisplayed, dataFiltered }"
87+
:is="footerComponent"
88+
/>
6389
</table>
6490
</div>
6591
</template>

src/demo/App.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const params2 = {
7373
cssClass: "minwidth",
7474
component: "vdt-actions",
7575
componentProps: { actions: ["view", "delete"] },
76+
collapsible: true,
7677
},
7778
],
7879
vKey: "id",
@@ -97,14 +98,14 @@ const params3 = {
9798
title: "Image",
9899
component: "CellImage",
99100
cssClass: "minwidth",
101+
collapsible: true,
100102
},
101103
],
102104
vKey: "id",
103105
};
104106

105107
export default {
106108
data() {
107-
108109
return {
109110
title: "UPDATE USER",
110111

src/parser/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export const globalDefaultColumn = {
1313
searchable: true,
1414
sortable: true,
1515
editable: false,
16+
collapsible: false,
17+
collapsed: false,
1618
type: "string",
17-
} as Column
19+
} as Column;
1820

1921
const type2searchFunction = {
2022
string: searchStringColumn as Function,
@@ -52,7 +54,6 @@ export function parseColumnProps(props: any) {
5254
// editable cell
5355
if (column.editable)
5456
column.component = 'vdt-cell-editable'
55-
// column.component = VdtTableCellEditable
5657

5758
// merge the column with the default values
5859
column = { ...globalDefaultColumn, ...defaultColumn, ...column }
@@ -85,4 +86,4 @@ export function parseTextProps(props: any): LanguageDict {
8586
const lang = props.lang as LanguageName
8687
const text = props.text as LanguageDict
8788
return { ...translations[lang], ...text }
88-
}
89+
}

src/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ type Column = {
1010
compareFunction: Function,
1111
component: VueComponent
1212
componentProps: VueComponentProps,
13+
collapsed: boolean,
14+
collapsible: boolean,
1315
displayIndex: number,
1416
editable: boolean,
1517
key: string,

0 commit comments

Comments
 (0)