Skip to content

Commit 138eae1

Browse files
authored
Merge pull request #39 from HC200ok/Fix/fixed-columns
fix:fixed-column-bug-in-safari
2 parents cadd882 + 7f2a641 commit 138eae1

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

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

src/components/DataTable.vue

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'show-shadow': showShadow,
1313
}"
1414
>
15-
<table>
15+
<table :class="{'fixed': fixedHeaders.length}">
1616
<colgroup>
1717
<col
1818
v-for="(header, index) in headersForRender"
@@ -25,8 +25,6 @@
2525
<th
2626
v-for="(header, index) in headersForRender"
2727
:key="index"
28-
colspan="1"
29-
rowspan="1"
3028
:class="{
3129
sortable: header.sortable,
3230
'none': header.sortable && header.sortType === 'none',
@@ -78,8 +76,6 @@
7876
<td
7977
v-for="(column, i) in headerColumns"
8078
:key="i"
81-
colspan="1"
82-
rowspan="1"
8379
:style="getFixedDistance(column, 'td')"
8480
:class="{'hasShadow': column === lastFixedColumn}"
8581
>
@@ -497,12 +493,6 @@ type FixedColumnsInfo = {
497493
width: number,
498494
};
499495
500-
const getColStyle = (header: HeaderForRender): string | undefined => {
501-
const width = header.width ?? (header.fixed ? 100 : null);
502-
if (width) return `width: ${width}px; min-width: ${width}px;`;
503-
return undefined;
504-
};
505-
506496
const hasFixedColumnsFromUser = computed(() => props.headers.findIndex((header) => header.fixed) !== -1);
507497
const fixedHeadersFromUser = computed(() => {
508498
if (hasFixedColumnsFromUser.value) return props.headers.filter((header) => header.fixed);
@@ -557,6 +547,12 @@ const lastFixedColumn = computed((): string => {
557547
return fixedHeaders.value[fixedHeaders.value.length - 1].value;
558548
});
559549
550+
const getColStyle = (header: HeaderForRender): string | undefined => {
551+
const width = header.width ?? (fixedHeaders.value.length ? 100 : null);
552+
if (width) return `width: ${width}px; min-width: ${width}px;`;
553+
return undefined;
554+
};
555+
560556
const fixedColumnsInfos = computed((): FixedColumnsInfo[] => {
561557
if (!fixedHeaders.value.length) return [];
562558
const fixedHeadersWidthArr = fixedHeaders.value.map((header) => header.width ?? 100);
@@ -1001,6 +997,9 @@ defineExpose({
1001997
}
1002998
1003999
table {
1000+
&.fixed {
1001+
table-layout: fixed;
1002+
}
10041003
display: table;
10051004
margin: 0px;
10061005
width: 100%;

src/modes/Client.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ const switchToNested = () => {
112112
};
113113
114114
const headers: Header[] = [
115-
{ text: 'Name', value: 'name', fixed: true, width: 200 },
115+
{ text: 'Name', value: 'name' },
116116
{ text: 'Address', value: 'address', width: 200 },
117-
{ text: 'Height', value: 'info.out.height', sortable: true, width: 200 },
118-
{ text: 'Weight', value: 'info.out.weight', sortable: true, width: 200 },
119-
{ text: 'Age', value: 'age', sortable: true, fixed: true, width: 200 },
117+
{ text: 'Height', value: 'info.out.height', sortable: true },
118+
{ text: 'Weight', value: 'info.out.weight', sortable: true },
119+
{ text: 'Age', value: 'age', sortable: true, width: 200 },
120120
{ text: 'Favourite sport', value: 'favouriteSport', width: 200 },
121121
{ text: 'Favourite fruits', value: 'favouriteFruits', width: 200 },
122122
];

0 commit comments

Comments
 (0)