@@ -3,65 +3,73 @@ import { Input } from "reactstrap";
33import { DataTableColumnDescription , DataTableActions , Filters , FilterTranslations } from "../DataTable/DataTableInterfaces" ;
44import { ColumnFilterType , ActionsPosition } from "../DataTable/DataTableTypes" ;
55import { ActionsHeaderFilterCell } from "../DataTable/Actions/ActionsHeaderFilterCell" ;
6+ import { getDeepValue } from "../Utils/DeepValue" ;
67
7- interface DataTableFilterRowProps < T > {
8+ interface DataTableFilterRowProps < T , TFilter > {
89 columns : DataTableColumnDescription < T > [ ] ;
910 actions ?: DataTableActions < T > ;
1011 actionsPosition ?: ActionsPosition ;
1112 translations : FilterTranslations ;
1213 filterPossible : boolean ;
14+ predefinedFilter ?: TFilter ;
1315 getFilterRefs ( ) : Filters ;
1416 setFilterRef ( filterName : string , ref : HTMLInputElement ) : void ;
1517 onSearch ( ) : void ;
1618}
1719
18- export function DataTableFilterRow < T > ( {
20+ export function DataTableFilterRow < T , TFilter > ( {
1921 columns,
2022 actions,
2123 actionsPosition,
2224 filterPossible = true ,
2325 translations,
26+ predefinedFilter,
2427 getFilterRefs,
2528 setFilterRef,
2629 onSearch,
27- } : DataTableFilterRowProps < T > ) {
30+ } : DataTableFilterRowProps < T , TFilter > ) {
2831 if ( ! filterPossible || columns . filter ( ( column ) => column . filter ) . length <= 0 ) return < React . Fragment /> ;
2932 return (
3033 < tr >
3134 { actionsPosition == ActionsPosition . Left && (
3235 < ActionsHeaderFilterCell < T > onSearch = { onSearch } translations = { translations } actions = { actions } getFilterRefs = { getFilterRefs } />
3336 ) }
34- { columns . map ( ( column ) => (
35- < th key = { column . dataField } >
36- { column . filter && column . filter . filterType === ColumnFilterType . String && (
37- < Input
38- bsSize = "sm"
39- id = { `filter-${ column . dataField } ` }
40- innerRef = { ( ref ) => ref && ref instanceof HTMLInputElement && setFilterRef ( column . dataField , ref ) }
41- onKeyDown = { ( e ) => {
42- if ( e . key === "Enter" ) onSearch ( ) ;
43- } }
44- />
45- ) }
46- { column . filter && column . filter . filterType === ColumnFilterType . Enum && column . enumValues && (
47- < Input
48- bsSize = "sm"
49- innerRef = { ( ref ) => ref && ref instanceof HTMLSelectElement && setFilterRef ( column . dataField , ref as HTMLInputElement ) }
50- type = "select"
51- onKeyDown = { ( e ) => {
52- if ( e . key === "Enter" ) onSearch ( ) ;
53- } }
54- onChange = { ( ) => onSearch ( ) }
55- >
56- { column . enumValues . map ( ( item ) => (
57- < option value = { item . value ?? "null" } key = { `${ column . dataField } _filter_${ item . value } ` } >
58- { item . text }
59- </ option >
60- ) ) }
61- </ Input >
62- ) }
63- </ th >
64- ) ) }
37+ { columns . map ( ( column ) => {
38+ var defaultValue = predefinedFilter ? getDeepValue ( predefinedFilter , column . dataField ) : undefined ;
39+ return (
40+ < th key = { column . dataField } >
41+ { column . filter && column . filter . filterType === ColumnFilterType . String && (
42+ < Input
43+ bsSize = "sm"
44+ id = { `filter-${ column . dataField } ` }
45+ innerRef = { ( ref ) => ref && ref instanceof HTMLInputElement && setFilterRef ( column . dataField , ref ) }
46+ defaultValue = { defaultValue }
47+ onKeyDown = { ( e ) => {
48+ if ( e . key === "Enter" ) onSearch ( ) ;
49+ } }
50+ />
51+ ) }
52+ { column . filter && column . filter . filterType === ColumnFilterType . Enum && column . enumValues && (
53+ < Input
54+ bsSize = "sm"
55+ innerRef = { ( ref ) => ref && ref instanceof HTMLSelectElement && setFilterRef ( column . dataField , ref as HTMLInputElement ) }
56+ type = "select"
57+ defaultValue = { defaultValue }
58+ onKeyDown = { ( e ) => {
59+ if ( e . key === "Enter" ) onSearch ( ) ;
60+ } }
61+ onChange = { ( ) => onSearch ( ) }
62+ >
63+ { column . enumValues . map ( ( item ) => (
64+ < option value = { item . value ?? "null" } key = { `${ column . dataField } _filter_${ item . value } ` } >
65+ { item . text }
66+ </ option >
67+ ) ) }
68+ </ Input >
69+ ) }
70+ </ th >
71+ ) ;
72+ } ) }
6573 { actionsPosition == ActionsPosition . Right && (
6674 < ActionsHeaderFilterCell < T > onSearch = { onSearch } translations = { translations } actions = { actions } getFilterRefs = { getFilterRefs } />
6775 ) }
0 commit comments