Skip to content

Commit

Permalink
[QTable] Remove thead if there are no values in columns (#37)
Browse files Browse the repository at this point in the history
* remove thead if there are no  values in columns
  • Loading branch information
Esvalirion authored Jan 19, 2021
1 parent d7e3a60 commit 720aab2
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/qComponents/QTable/src/QTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</template>
</colgroup>

<thead>
<thead v-if="doesHeaderExist">
<tr>
<th
v-if="selectable"
Expand Down Expand Up @@ -96,14 +96,14 @@
v-if="$scopedSlots.header"
name="header"
:data="column"
v-bind="updateItem(column, index, column.key)"
v-bind="updateColumnItem(column, index, column.key)"
/>

<slot
v-else-if="column.slots && column.slots.header"
:name="column.slots.header"
:data="column"
v-bind="updateItem(column, index, column.key)"
v-bind="updateColumnItem(column, index, column.key)"
/>

<template v-else>
Expand Down Expand Up @@ -188,14 +188,14 @@
v-if="$scopedSlots.total"
name="total"
:data="total"
v-bind="updateItem(total, index, column.key)"
v-bind="updateTotalItem(total, index, column.key)"
/>

<slot
v-else-if="column.slots && column.slots.total"
:name="column.slots.total"
:data="total"
v-bind="updateItem(total, index, column.key)"
v-bind="updateTotalItem(total, index, column.key)"
/>

<template v-else-if="total[column.key]">
Expand Down Expand Up @@ -452,6 +452,12 @@ export default {
}, []);
},
doesHeaderExist() {
return this.groupsOfColumns.some(({ columns }) =>
columns.some(({ value, slots }) => value?.toString() ?? slots?.header)
);
},
isDraggable() {
return this.groupsOfColumns.find(group => group.draggable);
},
Expand Down Expand Up @@ -858,21 +864,19 @@ export default {
};
},
updateItem(item, index, key) {
let value = null;
if (item[key] === 0 || Boolean(item[key])) {
value = item[key];
}
if (item.value) {
value = item.value;
}
updateColumnItem(item, index, key) {
return {
columnKey: key || null,
index,
value: item.value ?? null
};
},
updateTotalItem(item, index, key) {
return {
columnKey: key || null,
index,
value
value: item[key] ?? null
};
},
Expand Down

0 comments on commit 720aab2

Please sign in to comment.