72
72
<template v-for =" (item , itemIndex ) in computedItems " :key =" itemIndex " >
73
73
<tr
74
74
:class =" getRowClasses(item)"
75
- @click =" onRowClick(item, itemIndex, $event)"
76
- @dblclick =" onRowDblClick(item, itemIndex, $event)"
77
- @mouseenter =" onRowMouseEnter(item, itemIndex, $event)"
78
- @mouseleave =" onRowMouseLeave(item, itemIndex, $event)"
75
+ @click =" !filterEvent($event) && onRowClick(item, itemIndex, $event)"
76
+ @dblclick =" !filterEvent($event) && onRowDblClick(item, itemIndex, $event)"
77
+ @mouseenter =" !filterEvent($event) && onRowMouseEnter(item, itemIndex, $event)"
78
+ @mouseleave =" !filterEvent($event) && onRowMouseLeave(item, itemIndex, $event)"
79
79
>
80
80
<td
81
81
v-if =" addSelectableCell"
@@ -181,6 +181,7 @@ import {useBooleanish} from '../../composables'
181
181
import {cloneDeepAsync } from ' ../../utils/object'
182
182
import {titleCase } from ' ../../utils/stringUtils'
183
183
import BSpinner from ' ../BSpinner.vue'
184
+
184
185
import type {
185
186
Booleanish ,
186
187
ColorVariant ,
@@ -191,6 +192,7 @@ import type {
191
192
} from ' ../../types'
192
193
import type {BTableProvider , BTableSortCompare } from ' ../../types/components'
193
194
import BTableSimple from ' ./BTableSimple.vue'
195
+ import {filterEvent } from ' ./helpers/filter-event'
194
196
import useItemHelper from ' ./itemHelper'
195
197
196
198
type NoProviderTypes = ' paging' | ' sorting' | ' filtering'
@@ -297,7 +299,6 @@ interface BTableEmits {
297
299
}
298
300
299
301
const emit = defineEmits <BTableEmits >()
300
-
301
302
const slots = useSlots ()
302
303
303
304
const itemHelper = useItemHelper ()
@@ -314,7 +315,17 @@ const noProviderSortingBoolean = useBooleanish(toRef(props, 'showEmpty'))
314
315
const noProviderFilteringBoolean = useBooleanish (toRef (props , ' showEmpty' ))
315
316
316
317
const internalBusyFlag = ref (busyBoolean .value )
318
+ itemHelper .filterEvent .value = async (items ) => {
319
+ if (usesProvider .value ) {
320
+ await callItemsProvider ()
321
+ return
322
+ }
323
+ const clone = await cloneDeepAsync (items )
324
+ emit (' filtered' , clone )
325
+ }
326
+
317
327
const selectedItems = ref <Set <TableItem >>(new Set ([]))
328
+ const isSelecting = computed (() => selectedItems .value .size > 0 )
318
329
319
330
const tableClasses = computed (() => ({
320
331
[` align-${props .align } ` ]: props .align !== undefined ,
@@ -348,11 +359,18 @@ const computedFieldsTotal = computed(
348
359
)
349
360
350
361
const isFilterableTable = computed (() => props .filter !== undefined && props .filter !== ' ' )
351
-
352
362
const usesProvider = computed (() => props .provider !== undefined )
353
363
354
- const requireItemsMapping = computed (() => isSortable .value && sortInternalBoolean .value === true )
364
+ const addSelectableCell = computed (
365
+ () => selectableBoolean .value && (!! props .selectHead || slots .selectHead !== undefined )
366
+ )
367
+
368
+ const isSortable = computed (
369
+ () =>
370
+ props .fields .filter ((field ) => (typeof field === ' string' ? false : field .sortable )).length > 0
371
+ )
355
372
373
+ const requireItemsMapping = computed (() => isSortable .value && sortInternalBoolean .value === true )
356
374
const computedItems = computed (() => {
357
375
if (usesProvider .value ) return itemHelper .internalItems .value
358
376
return requireItemsMapping .value
@@ -364,53 +382,6 @@ const computedItems = computed(() => {
364
382
: props .items
365
383
})
366
384
367
- const addSelectableCell = computed (
368
- () => selectableBoolean .value && (!! props .selectHead || slots .selectHead !== undefined )
369
- )
370
- const isSortable = computed (
371
- () =>
372
- props .fields .filter ((field ) => (typeof field === ' string' ? false : field .sortable )).length > 0
373
- )
374
- const isSelecting = computed (() => selectedItems .value .size > 0 )
375
-
376
- watch (
377
- () => props .filter ,
378
- (filter , oldFilter ) => {
379
- if (filter === oldFilter || usesProvider .value ) return
380
- if (! filter ) {
381
- cloneDeepAsync (props .items ).then ((item ) => emit (' filtered' , item ))
382
- }
383
- }
384
- )
385
- watch (
386
- () => internalBusyFlag .value ,
387
- () => internalBusyFlag .value !== busyBoolean .value && emit (' update:busy' , internalBusyFlag .value )
388
- )
389
- watch (
390
- () => busyBoolean .value ,
391
- () => internalBusyFlag .value !== busyBoolean .value && (internalBusyFlag .value = busyBoolean .value )
392
- )
393
- watch (
394
- () => props .filter ,
395
- (val , oldVal ) => providerPropsWatch (' filter' , val , oldVal )
396
- )
397
- watch (
398
- () => props .currentPage ,
399
- (val , oldVal ) => providerPropsWatch (' currentPage' , val , oldVal )
400
- )
401
- watch (
402
- () => props .perPage ,
403
- (val , oldVal ) => providerPropsWatch (' perPage' , val , oldVal )
404
- )
405
- watch (
406
- () => props .sortBy ,
407
- (val , oldVal ) => providerPropsWatch (' sortBy' , val , oldVal )
408
- )
409
- watch (
410
- () => props .sortDesc ,
411
- (val , oldVal ) => providerPropsWatch (' sortDesc' , val , oldVal )
412
- )
413
-
414
385
const getFieldHeadLabel = (field : TableField ) => {
415
386
if (typeof field === ' string' ) return titleCase (field )
416
387
if (field .label !== undefined ) return field .label
@@ -430,7 +401,6 @@ const onRowClick = (row: TableItem, index: number, e: MouseEvent) => {
430
401
431
402
handleRowSelection (row , index , e .shiftKey )
432
403
}
433
-
434
404
const onRowDblClick = (row : TableItem , index : number , e : MouseEvent ) =>
435
405
emit (' rowDblClicked' , row , index , e )
436
406
@@ -440,15 +410,6 @@ const onRowMouseEnter = (row: TableItem, index: number, e: MouseEvent) =>
440
410
const onRowMouseLeave = (row : TableItem , index : number , e : MouseEvent ) =>
441
411
emit (' rowUnhovered' , row , index , e )
442
412
443
- itemHelper .filterEvent .value = async (items ) => {
444
- if (usesProvider .value ) {
445
- await callItemsProvider ()
446
- return
447
- }
448
- const clone = await cloneDeepAsync (items )
449
- emit (' filtered' , clone )
450
- }
451
-
452
413
const handleFieldSorting = (field : TableField ) => {
453
414
if (! isSortable .value ) return
454
415
@@ -554,29 +515,32 @@ const toggleRowDetails = (tr: TableItem) => {
554
515
const getFieldColumnClasses = (field : TableFieldObject ) => [
555
516
field .class ,
556
517
field .thClass ,
518
+ field .variant ? ` table-${field .variant } ` : undefined ,
557
519
{
558
- [` table-${field .variant } ` ]: field .variant !== undefined ,
559
520
' b-table-sortable-column' : isSortable .value && field .sortable ,
560
521
' b-table-sticky-column' : field .stickyColumn ,
561
522
},
562
523
]
524
+
563
525
const getFieldRowClasses = (field : TableFieldObject , tr : TableItem ) => [
564
526
field .class ,
565
527
field .tdClass ,
528
+ field .variant ? ` table-${field .variant } ` : undefined ,
566
529
tr ?._cellVariants && tr ?._cellVariants [field .key ]
567
530
? ` table-${tr ?._cellVariants [field .key ]} `
568
531
: undefined ,
569
532
{
570
- [` table-${field .variant } ` ]: field .variant !== undefined ,
571
533
' b-table-sticky-column' : field .stickyColumn ,
572
534
},
573
535
]
574
536
575
- const getRowClasses = (item : TableItem ) => ({
576
- [` table-${item ._rowVariant } ` ]: item ._rowVariant !== undefined ,
577
- [` selected table-${props .selectionVariant } ` ]:
578
- selectableBoolean .value && selectedItems .value .has (item ),
579
- })
537
+ const getRowClasses = (item : TableItem ) => [
538
+ item ._rowVariant ? ` table-${item ._rowVariant } ` : null ,
539
+ item ._rowVariant ? ` table-${item ._rowVariant } ` : null ,
540
+ selectableBoolean .value && selectedItems .value .has (item )
541
+ ? ` selected table-${props .selectionVariant } `
542
+ : null ,
543
+ ]
580
544
581
545
const selectAllRows = () => {
582
546
if (! selectableBoolean .value ) return
@@ -638,6 +602,45 @@ const providerPropsWatch = async (prop: string, val: any, oldVal: any) => {
638
602
await callItemsProvider ()
639
603
}
640
604
605
+ watch (
606
+ () => props .filter ,
607
+ (filter , oldFilter ) => {
608
+ if (filter === oldFilter || usesProvider .value ) return
609
+ if (! filter ) {
610
+ cloneDeepAsync (props .items ).then ((item ) => emit (' filtered' , item ))
611
+ }
612
+ }
613
+ )
614
+
615
+ watch (
616
+ () => internalBusyFlag .value ,
617
+ () => internalBusyFlag .value !== busyBoolean .value && emit (' update:busy' , internalBusyFlag .value )
618
+ )
619
+ watch (
620
+ () => busyBoolean .value ,
621
+ () => internalBusyFlag .value !== busyBoolean .value && (internalBusyFlag .value = busyBoolean .value )
622
+ )
623
+ watch (
624
+ () => props .filter ,
625
+ (val , oldVal ) => providerPropsWatch (' filter' , val , oldVal )
626
+ )
627
+ watch (
628
+ () => props .currentPage ,
629
+ (val , oldVal ) => providerPropsWatch (' currentPage' , val , oldVal )
630
+ )
631
+ watch (
632
+ () => props .perPage ,
633
+ (val , oldVal ) => providerPropsWatch (' perPage' , val , oldVal )
634
+ )
635
+ watch (
636
+ () => props .sortBy ,
637
+ (val , oldVal ) => providerPropsWatch (' sortBy' , val , oldVal )
638
+ )
639
+ watch (
640
+ () => props .sortDesc ,
641
+ (val , oldVal ) => providerPropsWatch (' sortDesc' , val , oldVal )
642
+ )
643
+
641
644
onMounted (() => {
642
645
if (usesProvider .value ) {
643
646
callItemsProvider ()
0 commit comments