Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix merge column and use init.dt event #5

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 50 additions & 23 deletions lib/core/LyxeaDatatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Action, { ActionArgs } from '@plugins/action/Action';
import DtButtons from './DtButtons';
import Filters from './Filters';
import LxRenderer from '@dto/Renderer';
import { default as jquery } from 'jquery';

//@ts-ignore
window.JSZip = jszip;
Expand Down Expand Up @@ -177,7 +178,7 @@ class LyxeaDatatable<T>
If columns in the standard object and in lxconfig, header generation is only based on lxconfig.
This allows you to generate the header with all the columns (and not just the columns defined in lxconfig).
*/
if (lxConfig.headers && standardColumns) {
if (lxConfig.headers && standardColumns && standardColumns.length) {
lxConfig.headers?.unshift({ columns: [...standardColumns] });
}
new LxRenderer(lxConfig);
Expand Down Expand Up @@ -253,25 +254,37 @@ class LyxeaDatatable<T>

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

if (lxConfig && lxConfig.scrollYFitToScreen)
this.scrollYFitToScreen(this.config);
jquery(`${this._ref}`).on('init.dt', (e, settings) => {
if (e.namespace !== 'dt') {
return;
}
const dtInstance = settings.oInstance.api();
/**
* Adding filter inputs
*/
if (lxConfig && lxConfig.filters) {
// @ts-ignore
this.#headerElement = new Filters(this.config, dtInstance).init(
this.#headerElement
);
}

/**
* Fit scrollY to screen
*/
if (lxConfig && lxConfig.scrollYFitToScreen) {
this.scrollYFitToScreen();
// Force redraw (FitToScreen has an effect on the draw event)
dtInstance.draw();
}
});
/**
* Initializing datatable
* Init event, get the datable instance on event.detail
*/
this.instance = new DataTable(`${this._ref}`, this.config);
this.refElement.dispatchEvent(this.initEvent(this.instance));

/**
* Adding filter inputs
*/
if (lxConfig && lxConfig.filters) {
this.#headerElement = new Filters(this.config, this.instance).init(
this.#headerElement
);
}

/**
* Handle issue with bootstrap tab nav
*/
Expand All @@ -283,24 +296,36 @@ class LyxeaDatatable<T>

__filterDataWithKey() {}

scrollYFitToScreen<T>(config: CustomDatatableConfig<T>) {
scrollYFitToScreen() {
const self = this;
// @ts-ignore
config.drawCallback = function () {
jquery(`${this._ref}`).on('draw.dt', (e, _) => {
if (e.namespace !== 'dt') {
return;
}
const tabPosition = document.querySelector(
`${self._ref}_wrapper`
) as HTMLElement;
if (tabPosition) {
const tabTop = tabPosition.getBoundingClientRect().top;
const dtScrollHeadHeight = (
document.querySelector(
(document.querySelector(
`${self._ref}_wrapper .dt-scroll-head`
) as HTMLElement
) as HTMLElement) || { offsetHeight: 0 }
).offsetHeight;
const dtTop = (
(document.querySelector(
`${self._ref}_wrapper .top`
) as HTMLElement) || { offsetHeight: 0 }
).offsetHeight;
const dtBottom = (
(document.querySelector(
`${self._ref}_wrapper .bottom`
) as HTMLElement) || { offsetHeight: 0 }
).offsetHeight;
const dtScrollFootHeight = (
document.querySelector(
(document.querySelector(
`${self._ref}_wrapper .dt-scroll-foot`
) as HTMLElement
) as HTMLElement) || { offsetHeight: 0 }
).offsetHeight;
const dtLayoutRows = document.querySelectorAll(
`${self._ref}_wrapper .dt-layout-row:not(.dt-layout-table)`
Expand All @@ -312,9 +337,11 @@ class LyxeaDatatable<T>
const myHeight =
window.innerHeight - // La taille de la fenêtre complete
tabTop - // L'ordonnée du haut du tableau
dtScrollHeadHeight - // La taille du header
dtScrollFootHeight - // La taille du footer
dtLayoutRowsHeight - // La taille de toutes les rows
dtTop - // La taille du top (lorsqu'on utilise `dom`)
dtBottom - // La taille du bottom (lorsqu'on utilise `dom`)
dtScrollHeadHeight - // La taille du header (lorsqu'on utilise `layout`)
dtScrollFootHeight - // La taille du footer (lorsqu'on utilise `layout`)
dtLayoutRowsHeight - // La taille de toutes les rows (lorsqu'on utilise `layout`)
10; // valeur statique pour assurer une marge
const dtScrollBody = document.querySelector(
`${self._ref}_wrapper .dt-scroll-body`
Expand All @@ -324,7 +351,7 @@ class LyxeaDatatable<T>
dtScrollBody.style.height = myHeight + 'px';
}
}
};
});
}

handleBootrapTabChange<T>(instance: DataTable<T>) {
Expand Down
9 changes: 6 additions & 3 deletions lib/dom/HeadersLxDom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ class HeaderLxDom extends AbstractLxDom {
);

if (!Object.keys(groupedHeaders).length) return this.headerRef;
// if no groupheader is present, build only columns
// if no groupheader is present, build only columns (e.g. : there are only HeaderGroup.NONE groups)
if (
Object.keys(groupedHeaders).length === 1 &&
Object.keys(groupedHeaders).some((el) => el.startsWith(HeaderGroup.NONE))
/*Object.keys(groupedHeaders).length === 1 ||
Object.keys(groupedHeaders).some((el) => el.startsWith(HeaderGroup.NONE))*/
!Object.keys(groupedHeaders).some(
(el) => !el.startsWith(HeaderGroup.NONE)
)
) {
const headerCells = this.$mainRowHeader(groupedHeaders);
const mainHeaderWrapper = this.$headerWrapper(
Expand Down
Loading