9
9
:class =" className"
10
10
cellpadding =" 0"
11
11
>
12
- <thead >
12
+ <thead
13
+ :class =" theadClassName"
14
+ >
13
15
<tr >
14
16
<th
15
17
v-for =" (field, i) in options.columns"
16
- :key =" i"
17
- :class =" field.className "
18
+ :key =" 'head_'+ i"
19
+ :class =" field.classHeaderName "
18
20
>
19
21
<slot
20
22
:name =" 'HEAD_'+field.name"
21
23
:field =" field"
22
24
:i =" i"
23
25
>
24
- <div v-html =" field.title" />
26
+ <input
27
+ v-if =" field.name === '_select_checkbox'"
28
+ type =" checkbox"
29
+ class =" select-all-checkbox d-print-none"
30
+ >
31
+ <div
32
+ v-else
33
+ v-html =" field.label"
34
+ />
25
35
</slot >
26
36
</th >
27
37
</tr >
28
38
</thead >
39
+ <tfoot
40
+ v-if =" !hideTfoot"
41
+ :class =" tfootClassName"
42
+ >
43
+ <tr >
44
+ <th
45
+ v-for =" (field, i) in options.columns"
46
+ :key =" 'foot_'+i"
47
+ :class =" field.classFooterName"
48
+ >
49
+ <slot
50
+ :name =" 'FOOT_'+field.name"
51
+ :field =" field"
52
+ :i =" i"
53
+ >
54
+ <input
55
+ v-if =" columnSearch && (field.searchable || typeof field.searchable === 'undefined')"
56
+ :placeholder =" field.label"
57
+ :class =" columnSearchClassName"
58
+ type =" search"
59
+ />
60
+ <div
61
+ v-else-if =" !columnSearch"
62
+ v-html =" field.label"
63
+ />
64
+ </slot >
65
+ </th >
66
+ </tr >
67
+ </tfoot >
29
68
</table >
30
69
</div >
31
70
</template >
@@ -54,6 +93,31 @@ export default {
54
93
type: String ,
55
94
default: ' table-responsive d-print-inline'
56
95
},
96
+ /**
97
+ * Set the input column search classes.
98
+ *
99
+ * @type String
100
+ */
101
+ columnSearchClassName: {
102
+ type: String ,
103
+ default: ' form-control form-control-sm'
104
+ },
105
+ /**
106
+ * Set the tfoot classes.
107
+ *
108
+ * @type String
109
+ */
110
+ tfootClassName: {
111
+ type: String ,
112
+ },
113
+ /**
114
+ * Set the thead classes.
115
+ *
116
+ * @type String
117
+ */
118
+ theadClassName: {
119
+ type: String ,
120
+ },
57
121
/**
58
122
* Set the table classes you wish to use, default with bootstrap4
59
123
* but you can override with: themeforest, foundation, etc..
@@ -123,6 +187,24 @@ export default {
123
187
hideFooter: {
124
188
type: Boolean
125
189
},
190
+ /**
191
+ * true to hide the tfoot of the table
192
+ *
193
+ * @type Boolean
194
+ */
195
+ hideTfoot: {
196
+ type: Boolean ,
197
+ default: true
198
+ },
199
+ /**
200
+ * true to hide the individual column search of the table
201
+ *
202
+ * @type Boolean
203
+ */
204
+ columnSearch: {
205
+ type: Boolean ,
206
+ default: false
207
+ },
126
208
/**
127
209
* The details column configuration of master/details.
128
210
*
@@ -173,27 +255,20 @@ export default {
173
255
const that = this
174
256
const jq = that .jq
175
257
258
+ let startCol = 0
259
+ let icol = 0
260
+
176
261
that .tableId = that .id || ` vdtnetable${ myUniqueId++ } `
177
262
178
263
// allow user to override default options
179
264
if (that .opts ) {
180
265
that .options = jq .extend ({}, that .options , that .opts )
181
266
}
182
- },
183
- mounted () {
184
- const that = this
185
- const jq = that .jq
186
- const $el = jq (that .$refs .table )
187
- const orders = []
188
-
189
- let startCol = 0
190
- let icol = 0
191
267
192
- // if fields are passed in, generate column definition
193
- // from our custom fields schema
194
268
if (that .fields ) {
195
269
const fields = that .fields
196
270
let cols = that .options .columns
271
+ let orders = that .options .order
197
272
198
273
for (let k in fields) {
199
274
const field = fields[k]
@@ -207,18 +282,14 @@ export default {
207
282
208
283
// generate
209
284
let col = {
210
- title : field .label || field .name ,
285
+ label : field .label || field .name ,
211
286
data: field .data || field .name ,
212
287
width: field .width ,
213
288
name: field .name ,
214
289
className: field .className ,
215
290
index: field .index || (icol + 1 )
216
291
}
217
292
218
- if (field .width ) {
219
- col .width = field .width
220
- }
221
-
222
293
if (field .hasOwnProperty (' defaultContent' )) {
223
294
col .defaultContent = field .defaultContent
224
295
}
@@ -236,21 +307,22 @@ export default {
236
307
}
237
308
238
309
if (field .hasOwnProperty (' editField' )) {
239
- col .editField = field .editField
310
+ col .editField = field .editField
240
311
}
241
312
242
- if (field .template || that . $scopedSlots [ field . name ] ) {
243
- field . render = that . compileTemplate ( field, that . $scopedSlots [ field . name ])
313
+ if (field .hasOwnProperty ( ' classHeaderName ' ) ) {
314
+ col . classHeaderName = field . classHeaderName
244
315
}
245
316
246
- if (field .render ) {
247
- if ( ! field .render . templated ) {
248
- let myRender = field . render
249
- field . render = function () {
250
- return myRender . apply (that, Array . prototype . slice . call ( arguments ))
251
- }
252
- }
317
+ if (field .hasOwnProperty ( ' classFooterName ' ) ) {
318
+ col . classFooterName = field .classFooterName
319
+ }
320
+
321
+ if ( field . template ) {
322
+ col . template = field . template
323
+ }
253
324
325
+ if (field .render ) {
254
326
col .render = field .render
255
327
}
256
328
@@ -263,14 +335,8 @@ export default {
263
335
264
336
icol++
265
337
}
266
-
267
- // sort columns
268
- cols = cols .sort ((a , b ) => a .index - b .index )
269
338
}
270
339
271
- // apply orders calculated from above
272
- that .options .order = that .options .order || orders
273
-
274
340
if (that .selectCheckbox ) {
275
341
that .selectCheckbox = that .selectCheckbox || 1
276
342
@@ -282,7 +348,6 @@ export default {
282
348
className: ' select-checkbox d-print-none' ,
283
349
data: null ,
284
350
defaultContent: ' ' ,
285
- title: ' <input type="checkbox" class="select-all-checkbox d-print-none">' ,
286
351
index: (that .selectCheckbox - 1 )
287
352
}
288
353
that .options .columns .splice (that .selectCheckbox - 1 , 0 , col)
@@ -325,13 +390,65 @@ export default {
325
390
that .options .order = [[startCol, ' asc' ]]
326
391
}
327
392
}
393
+ },
394
+ mounted () {
395
+ const that = this
396
+ const jq = that .jq
397
+ const $el = jq (that .$refs .table )
398
+ let cols = that .options .columns
399
+
400
+ for (let k in cols) {
401
+ const col = cols[k]
402
+
403
+ if (col .template || that .$scopedSlots [col .name ]) {
404
+ col .render = that .compileTemplate (col, that .$scopedSlots [col .name ])
405
+ }
406
+
407
+ if (col .render ) {
408
+ if (! col .render .templated ) {
409
+ let myRender = col .render
410
+ col .render = function () {
411
+ return myRender .apply (that, Array .prototype .slice .call (arguments ))
412
+ }
413
+ }
414
+ }
415
+
416
+ if (col .template ) {
417
+ delete col .template
418
+ }
419
+ }
328
420
329
421
// handle local data loader
330
422
if (that .dataLoader ) {
331
423
delete that .options .ajax
332
424
that .options .serverSide = false
333
425
}
334
426
427
+ if (! that .hideFooter && that .columnSearch ) {
428
+ that .options .initComplete = function () {
429
+ let api = this .api ();
430
+ let state = api .state .loaded ();
431
+
432
+ api .columns ().every (function () {
433
+ const that = this ;
434
+ const colIdx = this .index ();
435
+
436
+ if (state){
437
+ let colSearch = state .columns [colIdx].search ;
438
+ if (colSearch .search ){
439
+ jq (' input' , this .footer ()).val (colSearch .search );
440
+ }
441
+ }
442
+
443
+ jq (' input' , this .footer ()).on (' keyup change clear search' , function () {
444
+ if (that .search () !== this .value ) {
445
+ that .search (this .value ).draw ();
446
+ }
447
+ })
448
+ })
449
+ }
450
+ }
451
+
335
452
// you can access and update the that.options and $el here before we create the DataTable
336
453
that .$emit (' table-creating' , that, $el)
337
454
0 commit comments