Video Link :
Datatable will jump to top when we scroll to bottom. I think is due to the sticky header part.
Hi
//drive.google.com/file/d/1Chl7EvcmYQ2FmrmWicSa3fIu9R_OMfOy/view?usp=sharing
Could you pleae try with this updated ktui.js?
Place it somewhere in your Metronic v9 folder
Then you have to rebuild Metronic assets by updating this library config:
/metronic-tailwind-html/webpack.vendors.js
ktui: [
{
src: ["node_modules/@keenthemes/ktui/dist/ktui.min.js"],
dist: "/vendors/ktui/ktui.min.js",
},
],
hii, any update on this issue?
Hi
Do you have a public URL so we can check it further?
Thanks
hiii
u try to view at here
please add https:// in front
ams-demo.gamifierlabs.com/en/test
Hi
The problem probably is a race condition. The datatable initializes and fires first "kt.datatable.drew" event before script gets to run and attach listener. script misses the first event, and the sticky header isn't updated on the initial page load.
document.addEventListener("DOMContentLoaded", () => {
console.log("DATATABLE FIX (v2): Initializing sticky header fix...");
const headerElement = document.querySelector("#header");
const datatableElement = document.querySelector("[data-kt-datatable="true"]");
if (!datatableElement || !headerElement) {
console.error("DATATABLE FIX (v2): Could not find datatable or header element.");
return;
}
console.log("DATATABLE FIX (v2): Found datatable and header elements.");
const sticky = KTSticky.getOrCreateInstance(headerElement);
if (!sticky) {
console.error("DATATABLE FIX (v2): Could not get or create KTSticky instance.");
return;
}
console.log("DATATABLE FIX (v2): Sticky instance ready.");
// --- The Fix ---
// Check if the datatable has already been initialized.
// The "datatable-initialized" class is added after the first draw.
if (datatableElement.classList.contains("datatable-initialized")) {
console.log("DATATABLE FIX (v2): Datatable was already initialized. Manually calling sticky.update() once to fix initial state.");
sticky.update();
}
// Always attach the event listener for subsequent redraws (pagination, sorting, etc.)
datatableElement.addEventListener("kt.datatable.drew", function() {
console.log("DATATABLE FIX (v2): "kt.datatable.drew" event fired. Calling sticky.update().");
sticky.update();
});
console.log("DATATABLE FIX (v2): Event listener for "kt.datatable.drew" is now active for future redraws.");
});
hii, after replacing latest code, it still the same.
this line is not triggered
console.log("DATATABLE FIX (v2): "kt.datatable.drew" event fired. Calling sticky.update().");
here is my latest console
DATATABLE FIX (v2): Initializing sticky header fix...
DATATABLE FIX (v2): Found datatable and header elements.
DATATABLE FIX (v2): Sticky instance ready.
DATATABLE FIX (v2): Datatable was already initialized. Manually calling sticky.update() once to fix initial state.
DATATABLE FIX (v2): Event listener for 'kt.datatable.drew' is now active for future redraws.
Hi
I've added several console.log messages. If it still doesn't work, the output in your browser's developer console will tell us exactly where the breakdown is.
document.addEventListener("DOMContentLoaded", () => {
console.log("DATATABLE FIX: Initializing sticky header fix...");
// Using the corrected header selector for Demo 2
const headerElement = document.querySelector("#header");
const datatableElement = document.querySelector("[data-kt-datatable="true"]");
if (!datatableElement) {
console.error("DATATABLE FIX: Datatable element not found. Please check the selector `[data-kt-datatable="true"]`.");
return;
}
console.log("DATATABLE FIX: Datatable element found:", datatableElement);
if (!headerElement) {
console.error("DATATABLE FIX: Header element not found. Please check the selector `#header`.");
return;
}
console.log("DATATABLE FIX: Header element found:", headerElement);
// Use getOrCreateInstance to safely get the instance or create it if it doesn"t exist yet.
// This resolves potential timing issues.
const sticky = KTSticky.getOrCreateInstance(headerElement);
if (sticky) {
console.log("DATATABLE FIX: Successfully found or created KTSticky instance:", sticky);
datatableElement.addEventListener("kt.datatable.drew", function() {
console.log("DATATABLE FIX: "kt.datatable.drew" event fired. Calling sticky.update().");
sticky.update();
});
console.log("DATATABLE FIX: Event listener for "kt.datatable.drew" is now active.");
} else {
console.error("DATATABLE FIX: CRITICAL - Failed to get or create a KTSticky instance. The header element may be missing the `data-kt-sticky=\"true\"` attribute which is required for initialization.");
}
});
hiii this is my console
DATATABLE FIX: Initializing sticky header fix...
DATATABLE FIX: Datatable element found: <div data-kt-datatable=â"true" data-kt-datatable-page-size=â"100" id=â"formula_table" data-kt-datatable-initialized=â"true" class=â"datatable-initialized">â…â</div>â
DATATABLE FIX: Header element found: <header class=â"flex items-center shrink-0 bg-background h-(--header-height)â" data-kt-sticky=â"true" data-kt-sticky-class=â"transition-[height]â fixed z-10 top-0 left-0 right-0 backdrop-blur-md bg-white/â70 border-b border-border" data-kt-sticky-name=â"header" data-kt-sticky-offset=â"200px" id=â"header" data-kt-sticky-initialized=â"true">â…â</header>âflex
DATATABLE FIX: Successfully found or created KTSticky instance: t {_dataOptionPrefix: 'kt-', _uid: 'sticky1127136697941', _element: header#header.flex.items-center.shrink-0.bg-background.h-(--header-height), _name: 'sticky', _defaultConfig: {…}, …}
DATATABLE FIX: Event listener for 'kt.datatable.drew' is now active.
this part of console.log is not triggered
datatableElement.addEventListener("kt.datatable.drew", function() {
console.log("DATATABLE FIX: '.datatable.drew' event fired. Calling sticky.update().");
sticky.update();
});
please add https:// in front to view the image
ibb.co/66wTH7P
Hi
This occurs when paginating to a page with very few rows, which reduces the total height of the page and conflicts with the sticky header's positioning logic.
To resolve this, you need to add a small JavaScript snippet to your page. This script will ensure the sticky header repositions itself correctly every time the datatable is redrawn.
Add the following code to a script tag on the relevant page, or include it in your site's custom JavaScript file:
document.addEventListener("DOMContentLoaded", () => {
// Select the datatable and the sticky header elements
const datatableElement = document.querySelector("[data-kt-datatable="true"]");
const headerElement = document.querySelector("#kt_header");
// Ensure both elements exist before proceeding
if (!datatableElement || !headerElement) {
console.warn("Datatable or Header element not found. The sticky header fix will not be applied.");
return;
}
// Get the KTSticky instance for the header
const sticky = KTSticky.getInstance(headerElement);
if (sticky) {
// When the datatable finishes redrawing, update the sticky header"s position
datatableElement.addEventListener("kt.datatable.drew", function() {
sticky.update();
});
} else {
console.warn("Could not find KTSticky instance for the header element.");
}
});
hi i have try with your code, but it seem not working also.
const headerElement = document.querySelector("#kt_header");
In demo2, there the header id should be "header" rather than "kt_header", i already change to header but it seem like not working also. i tried to console log headerElement and datatableElement, it seem like the code able to select this two element. but when come to sticky.update(), this part of code is not working.
Hi,
Sorry for the late reply. May I know which demo are you using ? Can you paste here the URL from the preview site of the page where we can see this issue ? We allow only verified and internal URL posting. Otherwise spammers post multiple contents with spam urls.
Regards,
Sean
hi, i am using demo2. preview site don have such issue, because page content is too long. this problem only occur when the 1st page datatable cannot finish display data and move to the second page with only 1 or 2 row of data. When move to second page, the header should stick on the top, but due to the datatable only extra 1 or 2 row of data, the header cannot stick on top. so when u scroll to most bottom, it will cause the page shaking.
sorry i duno how to post the link. so i just post like this. Please add https:// in front
telemarketing.sgp1.cdn.digitaloceanspaces.com/280_1750515877.mp4