@@ -15,13 +15,13 @@ declare namespace Datatable {
15
15
16
16
type Filters = { [ F in Datatype ] ?: React . ReactNode } ;
17
17
18
- type Column < FieldNames extends string > = {
19
- field : FieldNames ;
18
+ type Column < Data extends Record < string , any > > = {
19
+ field : keyof Data ;
20
20
columnName : string ;
21
21
sortable : boolean ;
22
22
filterable : boolean ;
23
23
omit : boolean ;
24
- renderCell ?: ( value : any , column : Column < FieldNames > , row : Record < FieldNames , any > ) => React . ReactNode ;
24
+ renderCell ?: ( value : any , column : Column < Data > , row : Data ) => React . ReactNode ;
25
25
setOptions ?: string [ ] ;
26
26
multiFilter ?: boolean ;
27
27
} & ( {
@@ -35,16 +35,16 @@ declare namespace Datatable {
35
35
filterOperations ?: UseOperationFilter . BooleanFilterOperations [ ] ;
36
36
} )
37
37
38
- type RowOptionMenuProps = { row : Record < FieldNames , any > ; rowIndex : number ; }
38
+ type RowOptionMenuProps < Data extends Record < string , any > = Record < string , any > > = { row : Data ; rowIndex : number ; }
39
39
40
40
type AppsPanelProps = { OmitColumns : React . ReactNode ; }
41
41
42
- type ColumnConfig < FieldNames > = PartialKeys < Column < FieldNames > , "datatype" | "sortable" | "columnName" | "omit" | "filterable" > [ ] ;
42
+ type ColumnConfig < Data > = PartialKeys < Column < Data > , "datatype" | "sortable" | "columnName" | "omit" | "filterable" > [ ] ;
43
43
44
- interface Config < FieldNames > {
44
+ interface Config < Data extends Record < string , any > > {
45
45
46
- data : Data [ ] ;
47
- columns : Datatable . ColumnConfig < FieldNames > ;
46
+ data ? : Data [ ] ;
47
+ columns : Datatable . ColumnConfig < Data > ;
48
48
49
49
/**
50
50
* The total number of records in the database. (before pagination is applied)
@@ -54,12 +54,12 @@ declare namespace Datatable {
54
54
/**
55
55
* If serverSide is true, you need to handle the filters here and update data.
56
56
*/
57
- onFilter ?: ( filter : Filter < FieldNames > ) => void ;
57
+ onFilter ?: ( filter : Filter < Data > ) => void ;
58
58
59
- initialSortOrder ?: Filter < FieldNames > [ "sortOrder" ] ;
60
- initialPage ?: Filter < FieldNames > [ "page" ] ;
61
- initialOperationFilter ?: Filter < FieldNames > [ "operationFilter" ] ;
62
- initialSetFilter ?: Filter < FieldNames > [ "setFilter" ] ;
59
+ initialSortOrder ?: Filter < Data > [ "sortOrder" ] ;
60
+ initialPage ?: Filter < Data > [ "page" ] ;
61
+ initialOperationFilter ?: Filter < Data > [ "operationFilter" ] ;
62
+ initialSetFilter ?: Filter < Data > [ "setFilter" ] ;
63
63
64
64
/**
65
65
* Default is true
@@ -68,86 +68,86 @@ declare namespace Datatable {
68
68
}
69
69
70
70
71
- interface RichDatatableProps < Data extends Record < string , any > , FieldNames > {
71
+ interface RichDatatableProps < Data extends Record < string , any > > {
72
72
data ?: Data [ ] ;
73
73
isFetching ?: boolean ;
74
- columns : Datatable . ColumnConfig < FieldNames > ;
75
- setFilter : Datatable . UseSetFilter . HookReturn < FieldNames > ;
74
+ columns : Datatable . ColumnConfig < Data > ;
75
+ setFilter : Datatable . UseSetFilter . HookReturn < Data > ;
76
76
operationFilter : Datatable . UseOperationFilter . HookReturn < string > ;
77
- sortable : Datatable . UseSortable . HookReturn < FieldNames > ;
77
+ sortable : Datatable . UseSortable . HookReturn < Data > ;
78
78
pagination : Datatable . UsePagination . HookReturn ;
79
- selectable : Datatable . UseSelectable . HookReturn < FieldNames > ;
80
- RowOptionMenu ?: React . FC < RowOptionMenuProps > ;
79
+ selectable : Datatable . UseSelectable . HookReturn < Data > ;
80
+ RowOptionMenu ?: React . FC < RowOptionMenuProps < Data > > ;
81
81
AppsPanel ?: React . FC < AppsPanelProps > ;
82
- isSelectable ?: ( row : Record < FieldNames , any > ) => boolean ;
82
+ isSelectable ?: ( row : Data ) => boolean ;
83
83
NoData ?: React . ReactNode ;
84
- onRowClick ?: ( row : Record < FieldNames , any > , e : React . MouseEvent < HTMLDivElement , MouseEvent > ) => void ;
84
+ onRowClick ?: ( row : Data , e : React . MouseEvent < HTMLDivElement , MouseEvent > ) => void ;
85
85
showOptionsOnRowClick ?: boolean ;
86
86
}
87
87
88
- interface Filter < FieldNames > {
89
- sortOrder ? : UseSortable . SortOrder < FieldNames > ;
90
- page ? : UsePagination . Page ;
91
- operationFilter ? : UseOperationFilter . OperationFilter < TextFilterOperations | RangeFilterOperations | BooleanFilterOperations > ;
92
- setFilter ? : UseSetFilter . SetFilter < FieldNames > ;
88
+ interface Filter < Data extends Record < string , any > > {
89
+ sortOrder : UseSortable . SortOrder < Data > ;
90
+ page : UsePagination . Page ;
91
+ operationFilter : UseOperationFilter . OperationFilter < Data , UseOperationFilter . TextFilterOperations | UseOperationFilter . RangeFilterOperations | UseOperationFilter . BooleanFilterOperations > ;
92
+ setFilter : UseSetFilter . SetFilter < Data > ;
93
93
}
94
94
95
95
96
- interface TableHeaderProps < FieldNames extends string > extends React . PropsWithChildren {
97
- column : Column < FieldNames > ;
98
- onClick ?: ( column : Column < FieldNames > ) => void ;
96
+ interface TableHeaderProps < Data > extends React . PropsWithChildren {
97
+ column : Column < Data > ;
98
+ onClick ?: ( column : Column < Data > ) => void ;
99
99
className ?: string ;
100
100
}
101
101
102
102
type DatatableFilterProps < Operation > = { multiFilter ?: boolean ; setOptions ?: string [ ] ; datatype : string ; field : string ; filterOperations ?: Operation [ ] } ;
103
103
104
- interface DatatableProps < FieldNames extends string > {
105
- columns : Datatable . Column < FieldNames > [ ] ;
106
- data : Record < FieldNames , any > [ ] ;
104
+ interface DatatableProps < Data extends Record < string , any > > {
105
+ columns : Datatable . Column < Data > [ ] ;
106
+ data : Data [ ] ;
107
107
isFetching ?: boolean ;
108
- onColumnClick ?: ( column : Datatable . Column < FieldNames > ) => void ;
108
+ onColumnClick ?: ( column : Datatable . Column < Data > ) => void ;
109
109
110
- RowOptionMenu ?: React . FC < RowOptionMenuProps >
110
+ RowOptionMenu ?: React . FC < RowOptionMenuProps < Data > >
111
111
AppsPanel ?: React . ReactNode ;
112
112
113
- renderFilter ?: ( column : Datatable . Column < FieldNames > , FilterMenu : React . FC < { hasFilter : boolean ; } & React . PropsWithChildren > ) => React . ReactElement ;
114
- renderSort ?: ( column : Datatable . Column < FieldNames > ) => React . ReactElement ;
113
+ renderFilter ?: ( column : Datatable . Column < Data > , FilterMenu : React . FC < { hasFilter : boolean ; } & React . PropsWithChildren > ) => React . ReactElement ;
114
+ renderSort ?: ( column : Datatable . Column < Data > ) => React . ReactElement ;
115
115
Footer ?: React . ReactNode ;
116
116
117
117
hideSelect ?: boolean ;
118
118
SelectHeader ?: React . FC ;
119
- SelectCell ?: React . FC < { index : number ; row : Record < FieldNames , any > } > ;
119
+ SelectCell ?: React . FC < { index : number ; row : Data } > ;
120
120
NoData ?: React . ReactNode ;
121
- onRowClick ?: ( row : Record < FieldNames , any > , e : React . MouseEvent < HTMLDivElement , MouseEvent > ) => void ;
121
+ onRowClick ?: ( row : Data , e : React . MouseEvent < HTMLDivElement , MouseEvent > ) => void ;
122
122
showOptionsOnRowClick ?: boolean ;
123
123
}
124
124
125
125
126
126
127
127
namespace UseSortable {
128
128
129
- interface Config < FieldNames extends string > {
130
- initialSortOrder ?: SortOrder < FieldNames > ;
131
- onChange : ( sortOrder : SortOrder < FieldNames > ) => void ;
129
+ interface Config < Data extends Record < string , any > > {
130
+ initialSortOrder ?: SortOrder < Data > ;
131
+ onChange : ( sortOrder : SortOrder < Data > ) => void ;
132
132
}
133
133
134
- interface HookReturn < FieldNames extends string > {
135
- sortOrder : SortOrder < FieldNames > ;
136
- Sort : ( props : SortProps < FieldNames > ) => JSX . Element | null ;
137
- onSort : ( column : Column < FieldNames > ) => void
134
+ interface HookReturn < Data extends Record < string , any > > {
135
+ sortOrder : SortOrder < Data > ;
136
+ Sort : ( props : SortProps < Data > ) => JSX . Element | null ;
137
+ onSort : ( column : DatatableColumn < Data > ) => void
138
138
}
139
139
140
- interface SortProps < FieldNames extends string > {
141
- column : Column < FieldNames > ;
140
+ interface SortProps < Data > {
141
+ column : Column < Data > ;
142
142
sortDirection ?: SortDirection ;
143
143
orderIndex ?: number ;
144
144
isMultiSort : boolean ;
145
145
}
146
146
147
147
type SortDirection = "asc" | "desc"
148
148
149
- type SortOrder < FieldNames extends string > = {
150
- [ K in FieldNames ] ?: {
149
+ type SortOrder < Data extends Record < string , any > > = {
150
+ [ K in keyof Data ] ?: {
151
151
sortDirection : SortDirection ;
152
152
orderIndex : number ;
153
153
}
@@ -203,14 +203,14 @@ declare namespace Datatable {
203
203
204
204
namespace UseSelectable {
205
205
206
- interface Config < FieldNames > {
206
+ interface Config {
207
207
numberOfRows : number ;
208
208
onChange : ( selectable : { isAllSelected : boolean ; selectedRows : number [ ] } ) => void ;
209
209
}
210
210
211
- interface HookReturn < FieldNames > {
211
+ interface HookReturn {
212
212
Header : ( props : HeaderProps ) => JSX . Element | null ;
213
- Row : ( props : RowProps < FieldNames > ) => JSX . Element | null ;
213
+ Row : ( props : RowProps ) => JSX . Element | null ;
214
214
selectAll : ( select : boolean ) => void ;
215
215
selectedRows : number [ ] ;
216
216
onSelectRow : ( checked : boolean , rowIndex : number ) => void ;
@@ -223,7 +223,7 @@ declare namespace Datatable {
223
223
isAllSelected : boolean ;
224
224
}
225
225
226
- interface RowProps < FieldNames > {
226
+ interface RowProps {
227
227
index : number ;
228
228
disabled : boolean ;
229
229
checked : boolean ;
@@ -235,17 +235,17 @@ declare namespace Datatable {
235
235
236
236
namespace UseSetFilter {
237
237
238
- interface Config < FieldNames > {
239
- onChange : ( setFilter : SetFilter < FieldNames > ) => void ;
240
- initialSetFilter ?: SetFilter < FieldNames > ;
238
+ interface Config < Data extends Record < string , any > > {
239
+ onChange : ( setFilter : SetFilter < Data > ) => void ;
240
+ initialSetFilter ?: SetFilter < Data > ;
241
241
}
242
242
243
- type SetFilter < FieldNames > = { [ F in FieldNames ] ?: string [ ] } ;
243
+ type SetFilter < Data extends Record < string , any > > = { [ K in keyof Data ] ?: string [ ] } ;
244
244
245
- interface HookReturn < FieldNames > {
245
+ interface HookReturn < Data extends Record < string , any > > {
246
246
SetFilter : ( props : SetFilterProps ) => JSX . Element | null ;
247
- setFilter : SetFilter < FieldNames > ;
248
- onSetFilter : ( filter : SetFilter < FieldNames > ) => void ;
247
+ setFilter : SetFilter < Data > ;
248
+ onSetFilter : ( filter : SetFilter < Data > ) => void ;
249
249
}
250
250
251
251
@@ -272,14 +272,14 @@ declare namespace Datatable {
272
272
or ?: OperationValue < Operation >
273
273
}
274
274
275
- type OperationFilter < Operation > = {
276
- [ field : string ] : OperationValue < Operation >
275
+ type OperationFilter < Data extends Record < string , any > , Operation > = {
276
+ [ key : keyof Data ] : OperationValue < Operation >
277
277
} ;
278
278
279
- interface HookReturn < Operation > {
280
- OperationFilter : ( props : OperationProps < Operation > ) => JSX . Element | null ;
281
- operationFilter : OperationFilter < Operation > ;
282
- onSetOperationFilter : ( filter : OperationFilter < Operation > ) => void ;
279
+ interface HookReturn < Data extends Record < string , any > , Operation > {
280
+ OperationFilter : ( props : OperationProps < Data , Operation > ) => JSX . Element | null ;
281
+ operationFilter : OperationFilter < Data , Operation > ;
282
+ onSetOperationFilter : ( filter : OperationFilter < Data , Operation > ) => void ;
283
283
}
284
284
285
285
type BooleanFilterOperations = "Is true" | "Is false" | "Is blank" ;
@@ -288,10 +288,10 @@ declare namespace Datatable {
288
288
289
289
type TextFilterOperations = "Equal" | "Not equal" | "Contains" | "Starts with" | "Ends with" | "Is blank" ;
290
290
291
- interface OperationProps < Operation > {
291
+ interface OperationProps < Data extends Record < string , any > , Operation > {
292
292
inputType ?: "text" | "date" | "datetime-local" | "number" ;
293
- field : string ;
294
- onChange : ( result : UseOperationFilter . OperationFilter < Operation > ) => void ;
293
+ field : keyof Data ;
294
+ onChange : ( result : UseOperationFilter . OperationFilter < Data , Operation > ) => void ;
295
295
filterOperations ?: Operation [ ] ;
296
296
currentValue ?: UseOperationFilter . OperationValue < Operation >
297
297
allowedOperations : Operation [ ] ;
@@ -300,31 +300,37 @@ declare namespace Datatable {
300
300
}
301
301
}
302
302
303
- declare function BaseDatatable < FieldNames extends string > ( props : Datatable . DatatableProps < FieldNames > ) : react_jsx_runtime . JSX . Element ;
303
+ declare function BaseDatatable < Data extends Record < string , any > > ( props : Datatable . DatatableProps < Data > ) : react_jsx_runtime . JSX . Element ;
304
304
305
- declare function useDatatable < FieldNames > ( config : Datatable . Config < FieldNames > ) : {
306
- data : Record < string , any > [ ] ;
307
- columns : Datatable . ColumnConfig < FieldNames > ;
308
- sortable : Datatable . UseSortable . HookReturn < string > ;
305
+ declare function useDatatable < Data extends Record < string , any > > ( config : Datatable . Config < Data > ) : {
306
+ data : Data [ ] ;
307
+ columns : Datatable . ColumnConfig < Data > ;
308
+ sortable : Datatable . UseSortable . HookReturn < Data > ;
309
309
pagination : Datatable . UsePagination . HookReturn ;
310
- selectable : Datatable . UseSelectable . HookReturn < string > ;
311
- setFilter : Datatable . UseSetFilter . HookReturn < FieldNames > ;
312
- operationFilter : Datatable . UseOperationFilter . HookReturn < string > ;
313
- updateFilter : react . Dispatch < react . SetStateAction < Datatable . Filter < FieldNames > > > ;
310
+ selectable : Datatable . UseSelectable . HookReturn ;
311
+ setFilter : Datatable . UseSetFilter . HookReturn < Data > ;
312
+ operationFilter : Datatable . UseOperationFilter . HookReturn < Data , string > ;
313
+ updateFilter : react . Dispatch < react . SetStateAction < Datatable . Filter < Data > > > ;
314
314
Datatable : typeof RichDatatable ;
315
315
} ;
316
- declare function RichDatatable < Data extends Record < string , any > , FieldNames extends string > ( props : Datatable . RichDatatableProps < Data , FieldNames > ) : react_jsx_runtime . JSX . Element ;
316
+ declare function RichDatatable < Data extends Record < string , any > > ( props : Datatable . RichDatatableProps < Data > ) : react_jsx_runtime . JSX . Element ;
317
317
318
- interface Props < FieldNames extends string > {
319
- columns : Datatable . Column < FieldNames > [ ] ;
320
- setColumns : ( callback : ( columns : Datatable . Column < FieldNames > [ ] ) => Datatable . Column < FieldNames > [ ] ) => void ;
318
+ interface Props < Data extends Record < string , any > > {
319
+ columns : Datatable . Column < Data > [ ] ;
320
+ setColumns : ( callback : ( columns : Datatable . Column < Data > [ ] ) => Datatable . Column < Data > [ ] ) => void ;
321
321
}
322
- declare function OmitColumn < FieldNames extends string > ( config : Props < FieldNames > ) : react_jsx_runtime . JSX . Element ;
322
+ declare function OmitColumn < Data extends Record < string , any > > ( config : Props < Data > ) : react_jsx_runtime . JSX . Element ;
323
323
324
324
declare function usePagination ( config : Datatable . UsePagination . Config ) : Datatable . UsePagination . HookReturn ;
325
325
326
- declare function useSelectable < FieldNames extends string > ( config : Datatable . UseSelectable . Config < FieldNames > ) : Datatable . UseSelectable . HookReturn < FieldNames > ;
326
+ declare function useSelectable ( config : Datatable . UseSelectable . Config ) : Datatable . UseSelectable . HookReturn ;
327
+
328
+ declare function useSortable < Data extends Record < string , any > > ( config : Datatable . UseSortable . Config < Data > ) : Datatable . UseSortable . HookReturn < Data > ;
327
329
328
- declare function useSortable < FieldNames extends string > ( config : Datatable . UseSortable . Config < FieldNames > ) : Datatable . UseSortable . HookReturn < FieldNames > ;
330
+ declare function useClientSide < Data extends Record < string , any > > ( filter : Datatable . Filter < Data > , data ?: Data [ ] , count ?: number , serverSide ?: boolean ) : {
331
+ data : Data [ ] ;
332
+ count : number ;
333
+ numberOfRows : number ;
334
+ } ;
329
335
330
- export { BaseDatatable , Datatable , OmitColumn , useDatatable , usePagination , useSelectable , useSortable } ;
336
+ export { BaseDatatable , Datatable , OmitColumn , useClientSide , useDatatable , usePagination , useSelectable , useSortable } ;
0 commit comments