Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Commit 4c12337

Browse files
committed
Component for TH cell
1 parent de0d4f9 commit 4c12337

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

js/Components/HeaderCell.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script>
2+
export default {
3+
props: {
4+
cell: {
5+
type: Object,
6+
required: true,
7+
},
8+
},
9+
10+
methods: {
11+
onClick() {
12+
this.cell.onSort(this.cell.key);
13+
},
14+
},
15+
};
16+
</script>

js/InteractsWithQueryBuilder.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,40 @@ export default {
5757
});
5858
},
5959
60+
staticHeader(columnKey) {
61+
return this._headerCellData(columnKey, false);
62+
},
63+
64+
sortableHeader(columnKey) {
65+
return this._headerCellData(columnKey, true);
66+
},
67+
68+
_headerCellData(columnKey, sortable) {
69+
let sort = false;
70+
71+
if (this.queryBuilderData.sort === columnKey) {
72+
sort = "asc";
73+
} else if (this.queryBuilderData.sort === `-${columnKey}`) {
74+
sort = "desc";
75+
}
76+
77+
let show = true;
78+
79+
if (this.queryBuilderProps.columns) {
80+
const columnData = this.queryBuilderProps.columns[columnKey];
81+
82+
show = columnData ? columnData.enabled : true;
83+
}
84+
85+
return {
86+
key: columnKey,
87+
sort,
88+
show,
89+
sortable,
90+
onSort: this.sortBy,
91+
};
92+
},
93+
6094
sortBy(column) {
6195
this.queryBuilderData.page = 1;
6296
this.queryBuilderData.sort =

js/Tailwind2/HeaderCell.vue

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<template>
2+
<th v-show="cell.show" :class="{'cursor-pointer': cell.sortable }" @click.prevent="onClick">
3+
<span class="flex flex-row items-center">
4+
<slot />
5+
6+
<svg
7+
aria-hidden="true"
8+
class="w-3 h-3 ml-2"
9+
:class="{ 'text-gray-400': !cell.sort, 'text-green-500': cell.sort }"
10+
v-if="cell.sortable"
11+
xmlns="http://www.w3.org/2000/svg"
12+
viewBox="0 0 320 512"
13+
>
14+
<path
15+
v-if="!cell.sort"
16+
fill="currentColor"
17+
d="M41 288h238c21.4 0 32.1 25.9 17 41L177 448c-9.4 9.4-24.6 9.4-33.9 0L24 329c-15.1-15.1-4.4-41 17-41zm255-105L177 64c-9.4-9.4-24.6-9.4-33.9 0L24 183c-15.1 15.1-4.4 41 17 41h238c21.4 0 32.1-25.9 17-41z"
18+
/>
19+
20+
<path
21+
v-if="cell.sort === 'asc'"
22+
fill="currentColor"
23+
d="M279 224H41c-21.4 0-32.1-25.9-17-41L143 64c9.4-9.4 24.6-9.4 33.9 0l119 119c15.2 15.1 4.5 41-16.9 41z"
24+
/>
25+
26+
<path
27+
v-if="cell.sort === 'desc'"
28+
fill="currentColor"
29+
d="M41 288h238c21.4 0 32.1 25.9 17 41L177 448c-9.4 9.4-24.6 9.4-33.9 0L24 329c-15.1-15.1-4.4-41 17-41z"
30+
/>
31+
</svg>
32+
</span>
33+
</th>
34+
</template>
35+
36+
<script>
37+
import HeaderCell from "./../Components/HeaderCell.vue";
38+
39+
export default {
40+
mixins: [HeaderCell],
41+
};
42+
</script>

js/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import iwqb from './InteractsWithQueryBuilder.vue';
22
export const InteractsWithQueryBuilder = iwqb;
33

44
import ButtonWithDropdownComponent from './Components/ButtonWithDropdown.vue';
5+
import HeaderCellComponent from './Components/HeaderCell.vue';
56
import OnClickOutsideComponent from './Components/OnClickOutside.vue';
67
import PaginationComponent from './Components/Pagination.vue';
78
import TableAddSearchRowComponent from './Components/TableAddSearchRow.vue';
@@ -13,6 +14,7 @@ import TableSearchRowsComponent from './Components/TableSearchRows.vue';
1314

1415
export const Components = {
1516
ButtonWithDropdown: ButtonWithDropdownComponent,
17+
HeaderCell: HeaderCellComponent,
1618
OnClickOutside: OnClickOutsideComponent,
1719
Pagination: PaginationComponent,
1820
Table: TableComponent,
@@ -24,6 +26,7 @@ export const Components = {
2426
};
2527

2628
import Tailwind2ButtonWithDropdown from './Tailwind2/ButtonWithDropdown.vue';
29+
import Tailwind2HeaderCell from './Tailwind2/HeaderCell.vue';
2730
import Tailwind2Pagination from './Tailwind2/Pagination.vue';
2831
import Tailwind2Table from './Tailwind2/Table.vue';
2932
import Tailwind2TableAddSearchRow from './Tailwind2/TableAddSearchRow.vue';
@@ -35,6 +38,7 @@ import Tailwind2TableWrapper from './Tailwind2/TableWrapper.vue';
3538

3639
export const Tailwind2 = {
3740
ButtonWithDropdown: Tailwind2ButtonWithDropdown,
41+
HeaderCell: Tailwind2HeaderCell,
3842
Pagination: Tailwind2Pagination,
3943
Table: Tailwind2Table,
4044
TableAddSearchRow: Tailwind2TableAddSearchRow,

0 commit comments

Comments
 (0)