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 =" !hideFooter"
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,15 @@ export default {
123
187
hideFooter: {
124
188
type: Boolean
125
189
},
190
+ /**
191
+ * true to hide the individual column search of the table
192
+ *
193
+ * @type Boolean
194
+ */
195
+ columnSearch: {
196
+ type: Boolean ,
197
+ default: false
198
+ },
126
199
/**
127
200
* The details column configuration of master/details.
128
201
*
@@ -173,74 +246,67 @@ export default {
173
246
const that = this
174
247
const jq = that .jq
175
248
249
+ let startCol = 0
250
+ let icol = 0
251
+
176
252
that .tableId = that .id || ` vdtnetable${ myUniqueId++ } `
177
253
178
254
// allow user to override default options
179
255
if (that .opts ) {
180
256
that .options = jq .extend ({}, that .options , that .opts )
181
257
}
182
- },
183
- mounted () {
184
- const that = this
185
- const jq = that .jq
186
- const $el = jq (that .$refs .table )
187
- const orders = []
188
258
189
- let startCol = 0
190
- let icol = 0
191
-
192
- // if fields are passed in, generate column definition
193
- // from our custom fields schema
194
259
if (that .fields ) {
195
260
const fields = that .fields
196
261
let cols = that .options .columns
262
+ let orders = that .options .order
197
263
198
264
for (let k in fields) {
199
265
const field = fields[k]
200
266
field .name = field .name || k
201
267
202
268
// disable search and sort for local field
203
269
if (field .isLocal ) {
204
- field .searchable = false
205
- field .sortable = false
270
+ field .searchable = false
271
+ field .sortable = false
206
272
}
207
273
208
274
// generate
209
275
let col = {
210
- title: field .label || field .name ,
211
- data: field .data || field .name ,
212
- width: field .width ,
213
- name: field .name ,
214
- className: field .className ,
215
- index: field .index || (icol + 1 )
216
- }
217
-
218
- if (field .width ) {
219
- col .width = field .width
276
+ label: field .label || field .name ,
277
+ data: field .data || field .name ,
278
+ width: field .width ,
279
+ name: field .name ,
280
+ className: field .className ,
281
+ index: field .index || (icol + 1 )
220
282
}
221
283
222
284
if (field .hasOwnProperty (' defaultContent' )) {
223
- col .defaultContent = field .defaultContent
285
+ col .defaultContent = field .defaultContent
224
286
}
225
287
226
288
if (field .hasOwnProperty (' sortable' )) {
227
- col .orderable = field .sortable
289
+ col .orderable = field .sortable
228
290
}
229
291
230
292
if (field .hasOwnProperty (' visible' )) {
231
- col .visible = field .visible
293
+ col .visible = field .visible
232
294
}
233
295
234
296
if (field .hasOwnProperty (' searchable' )) {
235
- col .searchable = field .searchable
297
+ col .searchable = field .searchable
236
298
}
237
299
238
300
if (field .hasOwnProperty (' editField' )) {
239
301
col .editField = field .editField
240
302
}
241
303
242
- if (field .template || that .$scopedSlots [field .name ]) {
243
- field .render = that .compileTemplate (field, that .$scopedSlots [field .name ])
304
+ if (field .hasOwnProperty (' classHeaderName' )) {
305
+ col .classHeaderName = field .classHeaderName
306
+ }
307
+
308
+ if (field .hasOwnProperty (' classFooterName' )) {
309
+ col .classFooterName = field .classFooterName
244
310
}
245
311
246
312
if (field .render ) {
@@ -263,14 +329,8 @@ export default {
263
329
264
330
icol++
265
331
}
266
-
267
- // sort columns
268
- cols = cols .sort ((a , b ) => a .index - b .index )
269
332
}
270
333
271
- // apply orders calculated from above
272
- that .options .order = that .options .order || orders
273
-
274
334
if (that .selectCheckbox ) {
275
335
that .selectCheckbox = that .selectCheckbox || 1
276
336
@@ -282,7 +342,6 @@ export default {
282
342
className: ' select-checkbox d-print-none' ,
283
343
data: null ,
284
344
defaultContent: ' ' ,
285
- title: ' <input type="checkbox" class="select-all-checkbox d-print-none">' ,
286
345
index: (that .selectCheckbox - 1 )
287
346
}
288
347
that .options .columns .splice (that .selectCheckbox - 1 , 0 , col)
@@ -319,19 +378,38 @@ export default {
319
378
if (startCol > 0 ) {
320
379
if (that .options .order ) {
321
380
that .options .order .forEach ((v ) => {
322
- v[0 ] += startCol
381
+ v[0 ] += startCol
323
382
})
324
383
} else {
325
384
that .options .order = [[startCol, ' asc' ]]
326
385
}
327
386
}
387
+ },
388
+ mounted () {
389
+ const that = this
390
+ const jq = that .jq
391
+ const $el = jq (that .$refs .table )
328
392
329
393
// handle local data loader
330
394
if (that .dataLoader ) {
331
395
delete that .options .ajax
332
396
that .options .serverSide = false
333
397
}
334
398
399
+ if (! that .hideFooter && that .columnSearch ) {
400
+ that .options .initComplete = function () {
401
+ this .api ().columns ().every (function () {
402
+ const that = this ;
403
+
404
+ jq (' input' , this .footer ()).on (' keyup change clear search' , function () {
405
+ if (that .search () !== this .value ) {
406
+ that .search (this .value ).draw ();
407
+ }
408
+ })
409
+ })
410
+ }
411
+ }
412
+
335
413
// you can access and update the that.options and $el here before we create the DataTable
336
414
that .$emit (' table-creating' , that, $el)
337
415
0 commit comments