@@ -8,71 +8,72 @@ import type { GridThProps, DataGridContext } from '../data-grid-types';
8
8
import { useGridThSort , useGridThFilter , useGridThDrag } from '../composables/use-grid-th' ;
9
9
10
10
export default defineComponent ( {
11
- name : 'GridTh' ,
12
- props : gridThProps ,
13
- setup ( props : GridThProps ) {
14
- const ns = useNamespace ( 'data-grid' ) ;
15
- const { size, allChecked, halfAllChecked, virtualScroll, resizable, addGridThContextToMap, toggleAllRowChecked } = inject (
16
- DataGridInjectionKey
17
- ) as DataGridContext ;
18
- const { columnConfig, mouseenterCb, mouseleaveCb } = toRefs ( props ) ;
19
- const { direction, doSort, onSortClick, doClearSort } = useGridThSort ( columnConfig ) ;
20
- const { filterActive, setFilterStatus, onFilterChange } = useGridThFilter ( columnConfig ) ;
21
- const classes = computed ( ( ) => ( {
22
- [ ns . e ( 'th' ) ] : true ,
23
- [ ns . m ( columnConfig . value . align ) ] : true ,
24
- [ ns . e ( 'sticky-th' ) ] : true ,
25
- [ ns . em ( 'th' , size . value ) ] : true ,
26
- [ ns . em ( 'th' , 'filter-active' ) ] : filterActive . value ,
27
- [ ns . em ( 'th' , 'sort-active' ) ] : Boolean ( direction . value ) ,
28
- [ ns . em ( 'th' , 'operable' ) ] :
29
- columnConfig . value . filterable ||
30
- columnConfig . value . sortable ||
31
- ( ! virtualScroll . value && ( columnConfig . value . resizable ?? resizable . value ) ) ,
32
- } ) ) ;
33
- const { thRef, onMousedown } = useGridThDrag ( columnConfig ) ;
11
+ name : 'GridTh' ,
12
+ props : gridThProps ,
13
+ setup ( props : GridThProps ) {
14
+ const ns = useNamespace ( 'data-grid' ) ;
15
+ const { size, allChecked, halfAllChecked, virtualScroll, columnVirtualScroll, resizable, addGridThContextToMap, toggleAllRowChecked } =
16
+ inject ( DataGridInjectionKey ) as DataGridContext ;
17
+ const { columnConfig, mouseenterCb, mouseleaveCb } = toRefs ( props ) ;
18
+ const { direction, doSort, onSortClick, doClearSort } = useGridThSort ( columnConfig ) ;
19
+ const { filterActive, setFilterStatus, onFilterChange } = useGridThFilter ( columnConfig ) ;
20
+ const classes = computed ( ( ) => ( {
21
+ [ ns . e ( 'th' ) ] : true ,
22
+ [ ns . m ( columnConfig . value . align ) ] : true ,
23
+ [ ns . e ( 'sticky-th' ) ] : true ,
24
+ [ ns . em ( 'th' , size . value ) ] : true ,
25
+ [ ns . em ( 'th' , 'filter-active' ) ] : filterActive . value ,
26
+ [ ns . em ( 'th' , 'sort-active' ) ] : Boolean ( direction . value ) ,
27
+ [ ns . em ( 'th' , 'operable' ) ] :
28
+ columnConfig . value . filterable ||
29
+ columnConfig . value . sortable ||
30
+ ( ! ( columnVirtualScroll . value ?? virtualScroll . value ) && ( columnConfig . value . resizable ?? resizable . value ) ) ,
31
+ } ) ) ;
32
+ const { thRef, onMousedown } = useGridThDrag ( columnConfig ) ;
34
33
35
- if ( columnConfig . value . sortable ) {
36
- addGridThContextToMap ( columnConfig . value . field , { doSort, doClearSort } ) ;
37
- }
34
+ if ( columnConfig . value . sortable ) {
35
+ addGridThContextToMap ( columnConfig . value . field , { doSort, doClearSort } ) ;
36
+ }
38
37
39
- const cellTypeMap = {
40
- checkable : ( ) => < Checkbox modelValue = { allChecked . value } halfChecked = { halfAllChecked . value } onChange = { toggleAllRowChecked } /> ,
41
- index : ( ) => < span class = { ns . em ( 'th' , 'index' ) } > #</ span > ,
42
- default : ( ) => < span class = ' th-title' > { columnConfig . value . header } </ span > ,
43
- } ;
38
+ const cellTypeMap = {
39
+ checkable : ( ) => < Checkbox modelValue = { allChecked . value } halfChecked = { halfAllChecked . value } onChange = { toggleAllRowChecked } /> ,
40
+ index : ( ) => < span class = { ns . em ( 'th' , 'index' ) } > #</ span > ,
41
+ default : ( ) => < span class = " th-title" > { columnConfig . value . header } </ span > ,
42
+ } ;
44
43
45
- return ( ) => (
46
- < div
47
- ref = { thRef }
48
- class = { classes . value }
49
- style = { { width : columnConfig . value . width + 'px' } }
50
- onMousedown = { onMousedown }
51
- onMouseenter = { ( e ) => mouseenterCb . value ( e , columnConfig . value . showHeadOverflowTooltip ) }
52
- onMouseleave = { ( e ) => mouseleaveCb . value ( e , columnConfig . value . showHeadOverflowTooltip ) } >
53
- { columnConfig . value . headRender ? (
54
- < span class = 'th-title' > { columnConfig . value . headRender ( columnConfig . value ) } </ span >
55
- ) : (
56
- cellTypeMap [ columnConfig . value . type || 'default' ] ( )
57
- ) }
58
- { columnConfig . value . sortable && (
59
- < SortIcon
60
- class = { [ 'th-sort-icon' , direction . value , { 'th-sort-default-visible' : columnConfig . value . showSortIcon } ] }
61
- onClick = { onSortClick }
62
- />
63
- ) }
64
- { columnConfig . value . filterable && (
65
- < GridThFilter
66
- filterList = { columnConfig . value . filterList }
67
- multiple = { columnConfig . value . filterMultiple }
68
- showFilterIcon = { columnConfig . value . showFilterIcon }
69
- filterMenu = { columnConfig . value . filterMenu }
70
- setFilterStatus = { setFilterStatus }
71
- onFilterChange = { onFilterChange }
72
- />
73
- ) }
74
- { ! virtualScroll . value && ( columnConfig . value . resizable ?? resizable . value ) && < span class = 'resize-handle' > </ span > }
75
- </ div >
76
- ) ;
77
- } ,
78
- } ) ;
44
+ return ( ) => (
45
+ < div
46
+ ref = { thRef }
47
+ class = { classes . value }
48
+ style = { { width : columnConfig . value . width + 'px' } }
49
+ onMousedown = { onMousedown }
50
+ onMouseenter = { ( e ) => mouseenterCb . value ( e , columnConfig . value . showHeadOverflowTooltip ) }
51
+ onMouseleave = { ( e ) => mouseleaveCb . value ( e , columnConfig . value . showHeadOverflowTooltip ) } >
52
+ { columnConfig . value . headRender ? (
53
+ < span class = "th-title" > { columnConfig . value . headRender ( columnConfig . value ) } </ span >
54
+ ) : (
55
+ cellTypeMap [ columnConfig . value . type || 'default' ] ( )
56
+ ) }
57
+ { columnConfig . value . sortable && (
58
+ < SortIcon
59
+ class = { [ 'th-sort-icon' , direction . value , { 'th-sort-default-visible' : columnConfig . value . showSortIcon } ] }
60
+ onClick = { onSortClick }
61
+ />
62
+ ) }
63
+ { columnConfig . value . filterable && (
64
+ < GridThFilter
65
+ filterList = { columnConfig . value . filterList }
66
+ multiple = { columnConfig . value . filterMultiple }
67
+ showFilterIcon = { columnConfig . value . showFilterIcon }
68
+ filterMenu = { columnConfig . value . filterMenu }
69
+ setFilterStatus = { setFilterStatus }
70
+ onFilterChange = { onFilterChange }
71
+ />
72
+ ) }
73
+ { ! ( columnVirtualScroll . value ?? virtualScroll . value ) && ( columnConfig . value . resizable ?? resizable . value ) && (
74
+ < span class = "resize-handle" > </ span >
75
+ ) }
76
+ </ div >
77
+ ) ;
78
+ } ,
79
+ } ) ;
0 commit comments