|
@@ -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,7 +51,7 @@
|
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
|
56
|
<thead>
|
34
|
57
|
<tr class="dnd-moved">
|
|
@@ -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,87 +160,128 @@ 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
|
sortKey: {
|
172
|
|
- default: 'id',
|
|
198
|
+ default: "id"
|
173
|
199
|
},
|
174
|
200
|
hideItemCount: {
|
175
|
|
- default: false,
|
|
201
|
+ default: false
|
176
|
202
|
},
|
177
|
203
|
|
178
|
204
|
currentPage: {
|
179
|
|
- default: 1,
|
|
205
|
+ default: 1
|
180
|
206
|
},
|
181
|
207
|
bordered: {
|
182
|
|
- default: true,
|
|
208
|
+ default: true
|
183
|
209
|
},
|
184
|
210
|
striped: {
|
185
|
|
- default: true,
|
|
211
|
+ default: true
|
186
|
212
|
},
|
|
213
|
+ showColumnChooser: {
|
|
214
|
+ default: true
|
|
215
|
+ }
|
187
|
216
|
},
|
188
|
217
|
data() {
|
189
|
218
|
return {
|
190
|
219
|
hover: -1,
|
191
|
220
|
selectedItems: [],
|
192
|
221
|
showControl: false,
|
|
222
|
+ sortKey: "",
|
193
|
223
|
reverse: false,
|
194
|
|
- searchItem: '',
|
|
224
|
+ searchItem: "",
|
195
|
225
|
visibleItemsPerPageCount: 20,
|
196
|
226
|
itemsPerPageList: ItemsPerPageList,
|
|
227
|
+ visibleColumn: [],
|
|
228
|
+ allColumn: []
|
197
|
229
|
};
|
198
|
230
|
},
|
199
|
231
|
methods: {
|
|
232
|
+ checkItem(column, show) {
|
|
233
|
+ const list = [];
|
|
234
|
+ for (var i in this.allColumn) {
|
|
235
|
+ let item = this.allColumn[i];
|
|
236
|
+ if (item && item.column === column) {
|
|
237
|
+ item.show = show;
|
|
238
|
+ }
|
|
239
|
+ list.push(item);
|
|
240
|
+ }
|
|
241
|
+ this.allColumn = list;
|
|
242
|
+ },
|
|
243
|
+ getInitColumn() {
|
|
244
|
+ const list = [];
|
|
245
|
+ const listAll = [];
|
|
246
|
+ if (this.items) {
|
|
247
|
+ for (const i in Object.keys(this.items)) {
|
|
248
|
+ const item = this.items[i];
|
|
249
|
+ for (const o in Object.keys(item)) {
|
|
250
|
+ if (
|
|
251
|
+ !listAll.includes(Object.keys(item)[o]) &&
|
|
252
|
+ !Array.isArray(Object.values(item)[o])
|
|
253
|
+ ) {
|
|
254
|
+ const columnName = Object.keys(item)[o];
|
|
255
|
+ if (!listAll.some(x => x.column === columnName))
|
|
256
|
+ listAll.push({
|
|
257
|
+ column: columnName,
|
|
258
|
+ show: _.filter(listAll, x => x.show).length < this.columnCount
|
|
259
|
+ });
|
|
260
|
+ }
|
|
261
|
+ }
|
|
262
|
+ }
|
|
263
|
+ }
|
|
264
|
+ this.allColumn = listAll;
|
|
265
|
+ },
|
200
|
266
|
onClearSelected() {
|
201
|
267
|
this.selectedItems = [];
|
202
|
|
- this.$emit('onClearSelected');
|
|
268
|
+ this.$emit("onClearSelected");
|
203
|
269
|
},
|
204
|
270
|
isSelected(i) {
|
205
|
271
|
const ind = this.getActualIndex(i);
|
206
|
272
|
return _.some(this.selectedItems, x => x === ind);
|
207
|
273
|
},
|
208
|
274
|
onNew() {
|
209
|
|
- this.$emit('onNew');
|
|
275
|
+ this.$emit("onNew");
|
210
|
276
|
},
|
211
|
277
|
isObject(item) {
|
212
|
278
|
return !!item && item.constructor === Object;
|
213
|
279
|
},
|
214
|
280
|
onEdit(item) {
|
215
|
|
- this.$emit('onEdit', item);
|
|
281
|
+ this.$emit("onEdit", item);
|
216
|
282
|
},
|
217
|
283
|
onDelete(item) {
|
218
|
|
- this.$emit('onDelete', item);
|
|
284
|
+ this.$emit("onDelete", item);
|
219
|
285
|
},
|
220
|
286
|
onRowClick(item, i) {
|
221
|
287
|
const ind = this.getActualIndex(i);
|
|
@@ -227,7 +293,7 @@ export default {
|
227
|
293
|
}
|
228
|
294
|
this.selectedItems.push(ind);
|
229
|
295
|
}
|
230
|
|
- this.$emit('onRowClick', this.selectedItems);
|
|
296
|
+ this.$emit("onRowClick", this.selectedItems);
|
231
|
297
|
},
|
232
|
298
|
getActualIndex(index) {
|
233
|
299
|
return (this.currentPage - 1) * this.visibleItemsPerPageCount + index;
|
|
@@ -252,10 +318,10 @@ export default {
|
252
|
318
|
async pageChangeHandle(value) {
|
253
|
319
|
console.log(value);
|
254
|
320
|
switch (value) {
|
255
|
|
- case 'next':
|
|
321
|
+ case "next":
|
256
|
322
|
this.currentPage += 1;
|
257
|
323
|
break;
|
258
|
|
- case 'previous':
|
|
324
|
+ case "previous":
|
259
|
325
|
this.currentPage -= 1;
|
260
|
326
|
break;
|
261
|
327
|
default:
|
|
@@ -266,17 +332,17 @@ export default {
|
266
|
332
|
if (this.currentPage !== 1) {
|
267
|
333
|
this.currentPage = 1;
|
268
|
334
|
}
|
269
|
|
- },
|
|
335
|
+ }
|
270
|
336
|
},
|
271
|
337
|
computed: {
|
272
|
338
|
ListWidth() {
|
273
|
339
|
if (this.showControl) {
|
274
|
|
- return 'col-md-9';
|
|
340
|
+ return "col-md-9";
|
275
|
341
|
}
|
276
|
|
- return 'col-md-12';
|
|
342
|
+ return "col-md-12";
|
277
|
343
|
},
|
278
|
344
|
SortDirection() {
|
279
|
|
- return this.reverse ? 'desc' : 'asc';
|
|
345
|
+ return this.reverse ? "desc" : "asc";
|
280
|
346
|
},
|
281
|
347
|
PageCount() {
|
282
|
348
|
return this.visibleItemsPerPageCount !== 0
|
|
@@ -284,30 +350,34 @@ export default {
|
284
|
350
|
: 1;
|
285
|
351
|
},
|
286
|
352
|
Columns() {
|
|
353
|
+ const listColumns = [];
|
|
354
|
+ if (!this.allColumn || this.allColumn.length === 0) {
|
|
355
|
+ this.getInitColumn();
|
|
356
|
+ }
|
|
357
|
+ const list = _.filter(this.allColumn, x => x.show);
|
|
358
|
+ for (const i in list) {
|
|
359
|
+ const item = list[i];
|
|
360
|
+ if (item) {
|
|
361
|
+ listColumns.push(item.column);
|
|
362
|
+ }
|
|
363
|
+ }
|
|
364
|
+ return listColumns;
|
|
365
|
+ },
|
|
366
|
+ AllColumns() {
|
287
|
367
|
const list = [];
|
288
|
368
|
if (this.items) {
|
289
|
|
- for (const i in Object.keys(this.items)) {
|
290
|
|
- const item = this.items[i];
|
291
|
|
- for (const o in Object.keys(item)) {
|
292
|
|
- if (
|
293
|
|
- !list.includes(Object.keys(item)[o])
|
294
|
|
- && !Array.isArray(Object.values(item)[o])
|
295
|
|
- ) {
|
296
|
|
- if (list.length < this.columnCount) {
|
297
|
|
- list.push(Object.keys(item)[o]);
|
298
|
|
- }
|
299
|
|
- }
|
300
|
|
- }
|
301
|
|
- }
|
302
|
369
|
}
|
303
|
370
|
return list;
|
304
|
371
|
},
|
305
|
372
|
FilteredItems() {
|
306
|
|
- const list = _.filter(this.items, item => Object.values(item).some(
|
307
|
|
- i => JSON.stringify(i)
|
|
373
|
+ const list = _.filter(this.items, item =>
|
|
374
|
+ Object.values(item).some(
|
|
375
|
+ i =>
|
|
376
|
+ JSON.stringify(i)
|
308
|
377
|
.toLowerCase()
|
309
|
|
- .indexOf(this.searchItem.toLowerCase()) > -1,
|
310
|
|
- ),);
|
|
378
|
+ .indexOf(this.searchItem.toLowerCase()) > -1
|
|
379
|
+ )
|
|
380
|
+ );
|
311
|
381
|
return _.orderBy(list, this.sortKey, this.SortDirection);
|
312
|
382
|
},
|
313
|
383
|
DisplayItems() {
|
|
@@ -319,7 +389,8 @@ export default {
|
319
|
389
|
}
|
320
|
390
|
return list.slice(startSlice, endSlice);
|
321
|
391
|
},
|
322
|
|
- },
|
|
392
|
+ GetAllColumn() {}
|
|
393
|
+ }
|
323
|
394
|
};
|
324
|
395
|
</script>
|
325
|
396
|
<style scoped>
|
|
@@ -333,6 +404,10 @@ th[draggable] a {
|
333
|
404
|
text-decoration: none;
|
334
|
405
|
color: #333333;
|
335
|
406
|
}
|
|
407
|
+.table-striped > tbody > tr:nth-child(2n + 1) > td,
|
|
408
|
+.table-striped > tbody > tr:nth-child(2n + 1) > th {
|
|
409
|
+ background-color: rgba(225, 225, 225, 0.8);
|
|
410
|
+}
|
336
|
411
|
.active {
|
337
|
412
|
background-color: rgba(255, 255, 255, 0.5);
|
338
|
413
|
cursor: pointer;
|