|
@@ -12,6 +12,29 @@
|
12
|
12
|
</div>
|
13
|
13
|
<div class="p-2">
|
14
|
14
|
<div class="d-flex flex-row">
|
|
15
|
+ <div class="p2" v-if="showColumnChooser">
|
|
16
|
+ <div
|
|
17
|
+ class="btn btn-primary myBackground btn-width cursor-pointer"
|
|
18
|
+ data-toggle="modal"
|
|
19
|
+ data-target="#myModal"
|
|
20
|
+ >Column Chooser</div>
|
|
21
|
+ <div class="col-md-12">
|
|
22
|
+ <div id="myModal" class="modal fade" role="dialog">
|
|
23
|
+ <div class="modal-dialog modal-lg">
|
|
24
|
+ <!-- Modal content-->
|
|
25
|
+ <div class="modal-content">
|
|
26
|
+ <div class="modal-header">
|
|
27
|
+ <h5>Column Chooser</h5>
|
|
28
|
+ <button type="button" class="close" data-dismiss="modal">×</button>
|
|
29
|
+ </div>
|
|
30
|
+ <div style="margin-left:50px; margin-right:50px;margin-bottom:50px;">
|
|
31
|
+ <ListViewControl :items="allColumn" @checkItem="checkItem" />
|
|
32
|
+ </div>
|
|
33
|
+ </div>
|
|
34
|
+ </div>
|
|
35
|
+ </div>
|
|
36
|
+ </div>
|
|
37
|
+ </div>
|
15
|
38
|
<div class="p2" v-if="selectedItems.length > 0">
|
16
|
39
|
<div
|
17
|
40
|
class="btn btn-primary myBackground btn-width cursor-pointer"
|
|
@@ -28,9 +51,9 @@
|
28
|
51
|
<div v-if="items && items.length > 0" class="table-responsive">
|
29
|
52
|
<table
|
30
|
53
|
id="table"
|
31
|
|
- :class="{'table table-hover': (1 === 1), 'table-sm': compact, 'table-bordered': bordered, 'table-striped': striped}"
|
|
54
|
+ :class="{'table table-hover': (1 === 1), 'table-sm': compact, 'table-bordered': bordered}"
|
32
|
55
|
>
|
33
|
|
- <thead >
|
|
56
|
+ <thead>
|
34
|
57
|
<tr class="dnd-moved">
|
35
|
58
|
<th v-for="(column, c) in Columns" :key="c">
|
36
|
59
|
<div
|
|
@@ -115,15 +138,17 @@
|
115
|
138
|
</template>
|
116
|
139
|
|
117
|
140
|
<script>
|
118
|
|
-import _ from 'lodash';
|
119
|
|
-import ItemsPerPageList from '../../assets/staticData/itemsPerPage';
|
120
|
|
-import BasePagination from './basePagination.vue';
|
121
|
|
-import Alert from './alert.vue';
|
|
141
|
+import _ from "lodash";
|
|
142
|
+import ItemsPerPageList from "../../assets/staticData/itemsPerPage";
|
|
143
|
+import BasePagination from "./basePagination.vue";
|
|
144
|
+import Alert from "./alert.vue";
|
|
145
|
+import ListViewControl from "./listViewControl.vue";
|
122
|
146
|
|
123
|
147
|
export default {
|
124
|
148
|
components: {
|
125
|
149
|
BasePagination,
|
126
|
150
|
Alert,
|
|
151
|
+ ListViewControl
|
127
|
152
|
},
|
128
|
153
|
mounted() {
|
129
|
154
|
try {
|
|
@@ -135,51 +160,55 @@ export default {
|
135
|
160
|
} catch (error) {
|
136
|
161
|
throw error;
|
137
|
162
|
}
|
|
163
|
+ this.getInitColumn();
|
138
|
164
|
},
|
139
|
165
|
props: {
|
140
|
166
|
compact: {
|
141
|
|
- default: true,
|
|
167
|
+ default: true
|
142
|
168
|
},
|
143
|
169
|
allowSelect: {
|
144
|
|
- default: true,
|
|
170
|
+ default: true
|
145
|
171
|
},
|
146
|
172
|
allowMultipleSelect: {
|
147
|
|
- default: false,
|
|
173
|
+ default: false
|
148
|
174
|
},
|
149
|
175
|
hideSearch: {
|
150
|
|
- default: false,
|
|
176
|
+ default: false
|
151
|
177
|
},
|
152
|
178
|
showNew: {
|
153
|
|
- default: true,
|
|
179
|
+ default: true
|
154
|
180
|
},
|
155
|
181
|
items: undefined,
|
156
|
182
|
editable: {
|
157
|
|
- default: false,
|
|
183
|
+ default: false
|
158
|
184
|
},
|
159
|
185
|
deleteable: {
|
160
|
|
- default: false,
|
|
186
|
+ default: false
|
161
|
187
|
},
|
162
|
188
|
columnCount: {
|
163
|
|
- default: 6,
|
|
189
|
+ default: 6
|
164
|
190
|
},
|
165
|
191
|
showPager: {
|
166
|
|
- default: true,
|
|
192
|
+ default: true
|
167
|
193
|
},
|
168
|
194
|
title: {
|
169
|
|
- default: undefined,
|
|
195
|
+ default: undefined
|
170
|
196
|
},
|
171
|
197
|
hideItemCount: {
|
172
|
|
- default: false,
|
|
198
|
+ default: false
|
173
|
199
|
},
|
174
|
|
-
|
|
200
|
+
|
175
|
201
|
currentPage: {
|
176
|
202
|
default: 1
|
177
|
203
|
},
|
178
|
204
|
bordered: {
|
179
|
205
|
default: true
|
180
|
|
- },
|
|
206
|
+ },
|
181
|
207
|
striped: {
|
182
|
208
|
default: true
|
|
209
|
+ },
|
|
210
|
+ showColumnChooser: {
|
|
211
|
+ default: true
|
183
|
212
|
}
|
184
|
213
|
},
|
185
|
214
|
data() {
|
|
@@ -187,33 +216,69 @@ export default {
|
187
|
216
|
hover: -1,
|
188
|
217
|
selectedItems: [],
|
189
|
218
|
showControl: false,
|
190
|
|
- sortKey: '',
|
|
219
|
+ sortKey: "",
|
191
|
220
|
reverse: false,
|
192
|
|
- searchItem: '',
|
|
221
|
+ searchItem: "",
|
193
|
222
|
visibleItemsPerPageCount: 20,
|
194
|
223
|
itemsPerPageList: ItemsPerPageList,
|
|
224
|
+ visibleColumn: [],
|
|
225
|
+ allColumn: []
|
195
|
226
|
};
|
196
|
227
|
},
|
197
|
228
|
methods: {
|
|
229
|
+ checkItem(column, show) {
|
|
230
|
+ const list = [];
|
|
231
|
+ for (var i in this.allColumn) {
|
|
232
|
+ let item = this.allColumn[i];
|
|
233
|
+ if (item && item.column === column) {
|
|
234
|
+ item.show = show;
|
|
235
|
+ }
|
|
236
|
+ list.push(item);
|
|
237
|
+ }
|
|
238
|
+ this.allColumn = list;
|
|
239
|
+ },
|
|
240
|
+ getInitColumn() {
|
|
241
|
+ const list = [];
|
|
242
|
+ const listAll = [];
|
|
243
|
+ if (this.items) {
|
|
244
|
+ for (const i in Object.keys(this.items)) {
|
|
245
|
+ const item = this.items[i];
|
|
246
|
+ for (const o in Object.keys(item)) {
|
|
247
|
+ if (
|
|
248
|
+ !listAll.includes(Object.keys(item)[o]) &&
|
|
249
|
+ !Array.isArray(Object.values(item)[o])
|
|
250
|
+ ) {
|
|
251
|
+ const columnName = Object.keys(item)[o];
|
|
252
|
+ if (!listAll.some(x => x.column === columnName))
|
|
253
|
+ listAll.push({
|
|
254
|
+ column: columnName,
|
|
255
|
+ show: _.filter(listAll, x => x.show).length < this.columnCount
|
|
256
|
+ });
|
|
257
|
+ }
|
|
258
|
+ }
|
|
259
|
+ }
|
|
260
|
+ }
|
|
261
|
+ this.allColumn = listAll;
|
|
262
|
+ },
|
198
|
263
|
onClearSelected() {
|
199
|
264
|
this.selectedItems = [];
|
200
|
|
- this.$emit('onClearSelected');
|
|
265
|
+ this.$emit("onClearSelected");
|
201
|
266
|
},
|
202
|
267
|
isSelected(i) {
|
203
|
268
|
const ind = this.getActualIndex(i);
|
204
|
269
|
return _.some(this.selectedItems, x => x === ind);
|
205
|
270
|
},
|
206
|
271
|
onNew() {
|
207
|
|
- this.$emit('onNew');
|
|
272
|
+ this.$emit("onNew");
|
208
|
273
|
},
|
209
|
274
|
isObject(item) {
|
210
|
275
|
return !!item && item.constructor === Object;
|
211
|
276
|
},
|
212
|
277
|
onEdit(item) {
|
213
|
|
- this.$emit('onEdit', item);
|
|
278
|
+ this.$emit("onEdit", item);
|
214
|
279
|
},
|
215
|
280
|
onDelete(item) {
|
216
|
|
- this.$emit('onDelete', item);
|
|
281
|
+ this.$emit("onDelete", item);
|
217
|
282
|
},
|
218
|
283
|
onRowClick(item, i) {
|
219
|
284
|
const ind = this.getActualIndex(i);
|
|
@@ -225,7 +290,7 @@ export default {
|
225
|
290
|
}
|
226
|
291
|
this.selectedItems.push(ind);
|
227
|
292
|
}
|
228
|
|
- this.$emit('onRowClick', this.selectedItems);
|
|
293
|
+ this.$emit("onRowClick", this.selectedItems);
|
229
|
294
|
},
|
230
|
295
|
getActualIndex(index) {
|
231
|
296
|
return (this.currentPage - 1) * this.visibleItemsPerPageCount + index;
|
|
@@ -250,10 +315,10 @@ export default {
|
250
|
315
|
async pageChangeHandle(value) {
|
251
|
316
|
console.log(value);
|
252
|
317
|
switch (value) {
|
253
|
|
- case 'next':
|
|
318
|
+ case "next":
|
254
|
319
|
this.currentPage += 1;
|
255
|
320
|
break;
|
256
|
|
- case 'previous':
|
|
321
|
+ case "previous":
|
257
|
322
|
this.currentPage -= 1;
|
258
|
323
|
break;
|
259
|
324
|
default:
|
|
@@ -264,17 +329,17 @@ export default {
|
264
|
329
|
if (this.currentPage !== 1) {
|
265
|
330
|
this.currentPage = 1;
|
266
|
331
|
}
|
267
|
|
- },
|
|
332
|
+ }
|
268
|
333
|
},
|
269
|
334
|
computed: {
|
270
|
335
|
ListWidth() {
|
271
|
336
|
if (this.showControl) {
|
272
|
|
- return 'col-md-9';
|
|
337
|
+ return "col-md-9";
|
273
|
338
|
}
|
274
|
|
- return 'col-md-12';
|
|
339
|
+ return "col-md-12";
|
275
|
340
|
},
|
276
|
341
|
SortDirection() {
|
277
|
|
- return this.reverse ? 'desc' : 'asc';
|
|
342
|
+ return this.reverse ? "desc" : "asc";
|
278
|
343
|
},
|
279
|
344
|
PageCount() {
|
280
|
345
|
return this.visibleItemsPerPageCount !== 0
|
|
@@ -282,30 +347,34 @@ export default {
|
282
|
347
|
: 1;
|
283
|
348
|
},
|
284
|
349
|
Columns() {
|
|
350
|
+ const listColumns = [];
|
|
351
|
+ if (!this.allColumn || this.allColumn.length === 0) {
|
|
352
|
+ this.getInitColumn();
|
|
353
|
+ }
|
|
354
|
+ const list = _.filter(this.allColumn, x => x.show);
|
|
355
|
+ for (const i in list) {
|
|
356
|
+ const item = list[i];
|
|
357
|
+ if (item) {
|
|
358
|
+ listColumns.push(item.column);
|
|
359
|
+ }
|
|
360
|
+ }
|
|
361
|
+ return listColumns;
|
|
362
|
+ },
|
|
363
|
+ AllColumns() {
|
285
|
364
|
const list = [];
|
286
|
365
|
if (this.items) {
|
287
|
|
- for (const i in Object.keys(this.items)) {
|
288
|
|
- const item = this.items[i];
|
289
|
|
- for (const o in Object.keys(item)) {
|
290
|
|
- if (
|
291
|
|
- !list.includes(Object.keys(item)[o])
|
292
|
|
- && !Array.isArray(Object.values(item)[o])
|
293
|
|
- ) {
|
294
|
|
- if (list.length < this.columnCount) {
|
295
|
|
- list.push(Object.keys(item)[o]);
|
296
|
|
- }
|
297
|
|
- }
|
298
|
|
- }
|
299
|
|
- }
|
300
|
366
|
}
|
301
|
367
|
return list;
|
302
|
368
|
},
|
303
|
369
|
FilteredItems() {
|
304
|
|
- const list = _.filter(this.items, item => Object.values(item).some(
|
305
|
|
- i => JSON.stringify(i)
|
|
370
|
+ const list = _.filter(this.items, item =>
|
|
371
|
+ Object.values(item).some(
|
|
372
|
+ i =>
|
|
373
|
+ JSON.stringify(i)
|
306
|
374
|
.toLowerCase()
|
307
|
|
- .indexOf(this.searchItem.toLowerCase()) > -1,
|
308
|
|
- ),);
|
|
375
|
+ .indexOf(this.searchItem.toLowerCase()) > -1
|
|
376
|
+ )
|
|
377
|
+ );
|
309
|
378
|
return _.orderBy(list, this.sortKey, this.SortDirection);
|
310
|
379
|
},
|
311
|
380
|
DisplayItems() {
|
|
@@ -317,7 +386,8 @@ export default {
|
317
|
386
|
}
|
318
|
387
|
return list.slice(startSlice, endSlice);
|
319
|
388
|
},
|
320
|
|
- },
|
|
389
|
+ GetAllColumn() {}
|
|
390
|
+ }
|
321
|
391
|
};
|
322
|
392
|
</script>
|
323
|
393
|
<style scoped>
|
|
@@ -331,6 +401,10 @@ th[draggable] a {
|
331
|
401
|
text-decoration: none;
|
332
|
402
|
color: #333333;
|
333
|
403
|
}
|
|
404
|
+.table-striped > tbody > tr:nth-child(2n + 1) > td,
|
|
405
|
+.table-striped > tbody > tr:nth-child(2n + 1) > th {
|
|
406
|
+ background-color: rgba(225, 225, 225, 0.8);
|
|
407
|
+}
|
334
|
408
|
.active {
|
335
|
409
|
background-color: rgba(255, 255, 255, 0.5);
|
336
|
410
|
cursor: pointer;
|