@@ -49,6 +49,7 @@ export type LxConfigObject = {
49
49
headers ?: LxHeadersConfig ;
50
50
filters ?: boolean ;
51
51
handleBootrapTabChange ?: boolean ;
52
+ scrollYFitToScreen ?: boolean ;
52
53
row_action ?: {
53
54
width : string ;
54
55
className ?: string ;
@@ -121,6 +122,8 @@ class LyxeaDatatable<T>
121
122
config . lxConfig . filters = config . lxConfig . filters ?? true ;
122
123
config . lxConfig . handleBootrapTabChange =
123
124
config . lxConfig . handleBootrapTabChange ?? true ;
125
+ config . lxConfig . scrollYFitToScreen =
126
+ config . lxConfig . scrollYFitToScreen ?? false ;
124
127
}
125
128
126
129
return config ;
@@ -250,6 +253,9 @@ class LyxeaDatatable<T>
250
253
251
254
this . #dtButtons. parse ( this . config . buttons ) ;
252
255
256
+ if ( lxConfig && lxConfig . scrollYFitToScreen )
257
+ this . scrollYFitToScreen ( this . config ) ;
258
+
253
259
/**
254
260
* Initializing datatable
255
261
* Init event, get the datable instance on event.detail
@@ -277,6 +283,50 @@ class LyxeaDatatable<T>
277
283
278
284
__filterDataWithKey ( ) { }
279
285
286
+ scrollYFitToScreen < T > ( config : CustomDatatableConfig < T > ) {
287
+ const self = this ;
288
+ // @ts -ignore
289
+ config . drawCallback = function ( ) {
290
+ const tabPosition = document . querySelector (
291
+ `${ self . _ref } _wrapper`
292
+ ) as HTMLElement ;
293
+ if ( tabPosition ) {
294
+ const tabTop = tabPosition . getBoundingClientRect ( ) . top ;
295
+ const dtScrollHeadHeight = (
296
+ document . querySelector (
297
+ `${ self . _ref } _wrapper .dt-scroll-head`
298
+ ) as HTMLElement
299
+ ) . offsetHeight ;
300
+ const dtScrollFootHeight = (
301
+ document . querySelector (
302
+ `${ self . _ref } _wrapper .dt-scroll-foot`
303
+ ) as HTMLElement
304
+ ) . offsetHeight ;
305
+ const dtLayoutRows = document . querySelectorAll (
306
+ `${ self . _ref } _wrapper .dt-layout-row:not(.dt-layout-table)`
307
+ ) ;
308
+ const dtLayoutRowsHeight = Array . from ( dtLayoutRows ) . reduce (
309
+ ( acc , node ) => acc + ( node as HTMLElement ) . offsetHeight ,
310
+ 0
311
+ ) ;
312
+ const myHeight =
313
+ window . innerHeight - // La taille de la fenêtre complete
314
+ tabTop - // L'ordonnée du haut du tableau
315
+ dtScrollHeadHeight - // La taille du header
316
+ dtScrollFootHeight - // La taille du footer
317
+ dtLayoutRowsHeight - // La taille de toutes les rows
318
+ 10 ; // valeur statique pour assurer une marge
319
+ const dtScrollBody = document . querySelector (
320
+ `${ self . _ref } _wrapper .dt-scroll-body`
321
+ ) as HTMLElement ;
322
+ if ( tabTop + tabPosition . offsetHeight > window . innerHeight ) {
323
+ dtScrollBody . style . minHeight = myHeight + 'px' ;
324
+ dtScrollBody . style . height = myHeight + 'px' ;
325
+ }
326
+ }
327
+ } ;
328
+ }
329
+
280
330
handleBootrapTabChange < T > ( instance : DataTable < T > ) {
281
331
// For JQUERY user
282
332
if ( typeof $ == 'function' ) {
0 commit comments