-
Notifications
You must be signed in to change notification settings - Fork 74
/
RowClicked.vue
executable file
·188 lines (178 loc) · 4.51 KB
/
RowClicked.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<template>
<table-lite
:has-checkbox="true"
:is-loading="table.isLoading"
:is-re-search="table.isReSearch"
:columns="table.columns"
:rows="table.rows"
:rowClasses="table.rowClasses"
:total="table.totalRecordCount"
:sortable="table.sortable"
:messages="table.messages"
@do-search="doSearch"
@is-finished="tableLoadingFinish"
@return-checked-rows="updateCheckedRows"
@row-clicked="rowClicked"
></table-lite>
</template>
<script>
import { defineComponent, reactive } from "vue";
import TableLite from "../components/TableLite.vue";
// Fake Data for 'asc' sortable
const sampleData1 = (offst, limit) => {
offst = offst + 1;
let data = [];
for (let i = offst; i <= limit; i++) {
data.push({
id: i,
name: "TEST" + i,
email: "test" + i + "@example.com",
});
}
return data;
};
// Fake Data for 'desc' sortable
const sampleData2 = (offst, limit) => {
let data = [];
for (let i = limit; i > offst; i--) {
data.push({
id: i,
name: "TEST" + i,
email: "test" + i + "@example.com",
});
}
return data;
};
export default defineComponent({
name: "App",
components: { TableLite },
setup() {
// Table config
const table = reactive({
isLoading: false,
isReSearch: false,
rowClasses: (row) => {
if (row.id == 1) {
return ["aaa", "is-id-one"];
}
return ["bbb", "other"];
},
columns: [
{
label: "ID",
field: "id",
width: "3%",
sortable: true,
isKey: true,
},
{
label: "Name",
field: "name",
width: "10%",
sortable: true,
display: function (row) {
return (
'<a href="#" data-id="' +
row.id +
'" class="is-rows-el name-btn">' +
row.name +
"</a>"
);
},
},
{
label: "Email",
field: "email",
width: "15%",
sortable: true,
},
{
label: "",
field: "quick",
width: "10%",
display: function (row) {
return (
'<button type="button" data-id="' +
row.id +
'" class="is-rows-el quick-btn">Button</button>'
);
},
},
],
rows: [],
totalRecordCount: 0,
sortable: {
order: "id",
sort: "asc",
},
messages: {
pagingInfo: "Showing {0}-{1} of {2}",
pageSizeChangeLabel: "Row count:",
gotoPageLabel: "Go to page:",
noDataAvailable: "No data",
},
});
/**
* Search Event
*/
const doSearch = (offset, limit, order, sort) => {
table.isLoading = true;
setTimeout(() => {
table.isReSearch = offset == undefined ? true : false;
if (offset >= 10 || limit >= 20) {
limit = 20;
}
if (sort == "asc") {
table.rows = sampleData1(offset, limit);
} else {
table.rows = sampleData2(offset, limit);
}
table.totalRecordCount = 20;
table.sortable.order = order;
table.sortable.sort = sort;
}, 600);
};
/**
* Loading finish event
*/
const tableLoadingFinish = (elements) => {
table.isLoading = false;
Array.prototype.forEach.call(elements, function (element) {
if (element.classList.contains("name-btn")) {
element.addEventListener("click", function (event) {
event.stopPropagation(); // prevents further propagation of the current event in the capturing and bubbling phases.
console.log(this.dataset.id + " name-btn click!!");
});
}
if (element.classList.contains("quick-btn")) {
element.addEventListener("click", function (event) {
event.stopPropagation(); // prevents further propagation of the current event in the capturing and bubbling phases.
console.log(this.dataset.id + " quick-btn click!!");
});
}
});
};
/**
* Row checked event
*/
const updateCheckedRows = (rowsKey) => {
console.log(rowsKey);
};
// First get data
doSearch(0, 10, "id", "asc");
/**
* Row clicked event
*/
const rowClicked = (row) => {
console.log("Row clicked!", row);
};
return {
table,
doSearch,
tableLoadingFinish,
updateCheckedRows,
rowClicked,
};
},
});
</script>