File tree 4 files changed +47
-8
lines changed
4 files changed +47
-8
lines changed Original file line number Diff line number Diff line change @@ -886,7 +886,8 @@ export default {
886
886
As mentioned in the [ ** Fields** ] ( #fields-column-definitions- ) section above,
887
887
you can make columns sortable. Clicking on a sortable column header will sort the
888
888
column in ascending direction (smallest first), while clicking on it again will switch the direction
889
- of sorting. Clicking on a non-sortable column will clear the sorting.
889
+ of sorting. Clicking on a non-sortable column will clear the sorting. The prop ` no-sort-reset `
890
+ can be used to disable this feature.
890
891
891
892
You can control which column is pre-sorted and the order of sorting (ascending or
892
893
descending). To pre-specify the column to be sorted, set the ` sort-by ` prop to
Original file line number Diff line number Diff line change @@ -13,16 +13,18 @@ <h2>Basic table</h2>
13
13
</ template >
14
14
</ b-table >
15
15
16
- < b-table ref ="table_stacked " striped hover stacked :items ="items " :fields ="fields ">
17
- < template slot ="name " slot-scope ="data ">
18
- {{ data.value.first }} {{ data.value.last }}
19
- </ template >
20
- </ b-table >
16
+ < b-table ref ="table_stacked " striped hover stacked :items ="items " :fields ="fields ">
17
+ < template slot ="name " slot-scope ="data ">
18
+ {{ data.value.first }} {{ data.value.last }}
19
+ </ template >
20
+ </ b-table >
21
21
22
- < b-table ref ="table_without_fields " :items ="secondaryItems "> </ b-table >
22
+ < b-table ref ="table_without_fields " :items ="secondaryItems "> </ b-table >
23
23
24
24
< b-table ref ="table_responsive " responsive :items ="items " :fields ="fields "> </ b-table >
25
25
26
+ < b-table ref ="table_no_sort_reset " :items ="items " :fields ="fields " no-sort-reset > </ b-table >
27
+
26
28
< h2 > Paginated Table</ h2 >
27
29
< div class ="my-1 row ">
28
30
< div class ="col-6 ">
Original file line number Diff line number Diff line change @@ -527,6 +527,10 @@ export default {
527
527
type : Boolean ,
528
528
default : false
529
529
} ,
530
+ noSortReset : {
531
+ type : Boolean ,
532
+ default : false
533
+ } ,
530
534
busy : {
531
535
type : Boolean ,
532
536
default : false
@@ -928,7 +932,7 @@ export default {
928
932
this . localSortDesc = false
929
933
}
930
934
sortChanged = true
931
- } else if ( this . localSortBy ) {
935
+ } else if ( this . localSortBy && ! this . noSortReset ) {
932
936
this . localSortBy = null
933
937
this . localSortDesc = false
934
938
sortChanged = true
Original file line number Diff line number Diff line change @@ -528,6 +528,38 @@ describe('table', async () => {
528
528
}
529
529
} )
530
530
531
+ it ( 'non-sortable header th should not emit a sort-changed event when clicked and prop no-sort-reset is set' , async ( ) => {
532
+ const { app : { $refs } } = window
533
+ const vm = $refs . table_no_sort_reset
534
+ const spy = jest . fn ( )
535
+ const fieldKeys = Object . keys ( vm . fields )
536
+
537
+ vm . $on ( 'sort-changed' , spy )
538
+ const thead = [ ...vm . $el . children ] . find ( el => el && el . tagName === 'THEAD' )
539
+ expect ( thead ) . toBeDefined ( )
540
+ if ( thead ) {
541
+ const tr = [ ...thead . children ] . find ( el => el && el . tagName === 'TR' )
542
+ expect ( tr ) . toBeDefined ( )
543
+ if ( tr ) {
544
+ let sortBy = null
545
+ const ths = [ ...tr . children ]
546
+ expect ( ths . length ) . toBe ( fieldKeys . length )
547
+ ths . forEach ( ( th , idx ) => {
548
+ th . click ( )
549
+ if ( vm . fields [ fieldKeys [ idx ] ] . sortable ) {
550
+ expect ( spy ) . toHaveBeenCalledWith ( vm . context )
551
+ expect ( vm . context . sortBy ) . toBe ( fieldKeys [ idx ] )
552
+ sortBy = vm . context . sortBy
553
+ } else {
554
+ expect ( spy ) . not . toHaveBeenCalled ( )
555
+ expect ( vm . context . sortBy ) . toBe ( sortBy )
556
+ }
557
+ spy . mockClear ( )
558
+ } )
559
+ }
560
+ }
561
+ } )
562
+
531
563
it ( 'table_paginated pagination works' , async ( ) => {
532
564
const { app : { $refs } } = window
533
565
const vm = $refs . table_paginated
You can’t perform that action at this time.
0 commit comments