Skip to content

Commit 6592d6a

Browse files
authored
Merge pull request #4 from geohyd/develop
feat: Adding scrollYFitToScreen properties
2 parents af940e3 + a96f43c commit 6592d6a

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ The following sections are dedicated to this configuration.
7575
| headers | headers and cols definition | - |
7676
| filters | False | true |
7777
| handleBootrapTabChange | Handle the issue with bootstrap where the click on tab nav broke the datatable headers | true |
78+
| scrollYFitToScreen | Set the scrollY to automatically fit the screen | false |
7879
| row_action | Provide action you can define and add a column at the end of the DataTable | - |
7980
| columnsDefaultKey | Provide a default key for each column. Overriden by the key `defaultValue` in columns definition | - |
8081

lib/core/LyxeaDatatable.ts

+50
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export type LxConfigObject = {
4949
headers?: LxHeadersConfig;
5050
filters?: boolean;
5151
handleBootrapTabChange?: boolean;
52+
scrollYFitToScreen?: boolean;
5253
row_action?: {
5354
width: string;
5455
className?: string;
@@ -121,6 +122,8 @@ class LyxeaDatatable<T>
121122
config.lxConfig.filters = config.lxConfig.filters ?? true;
122123
config.lxConfig.handleBootrapTabChange =
123124
config.lxConfig.handleBootrapTabChange ?? true;
125+
config.lxConfig.scrollYFitToScreen =
126+
config.lxConfig.scrollYFitToScreen ?? false;
124127
}
125128

126129
return config;
@@ -250,6 +253,9 @@ class LyxeaDatatable<T>
250253

251254
this.#dtButtons.parse(this.config.buttons);
252255

256+
if (lxConfig && lxConfig.scrollYFitToScreen)
257+
this.scrollYFitToScreen(this.config);
258+
253259
/**
254260
* Initializing datatable
255261
* Init event, get the datable instance on event.detail
@@ -277,6 +283,50 @@ class LyxeaDatatable<T>
277283

278284
__filterDataWithKey() {}
279285

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+
280330
handleBootrapTabChange<T>(instance: DataTable<T>) {
281331
// For JQUERY user
282332
if (typeof $ == 'function') {

0 commit comments

Comments
 (0)