Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

onClick event on <a> or <button> is not working inside Metronic Tailwind DataTable column with NextJs


Hi

I am using Metronic v9.1.2 Tailwind with nextjs v15. But onClick is not working inside the <tbody><tr><td> of KTDataTable. Please tell how to make this onClick work ?

Whereas if i disable KTDataTable initialization then onClick work fine.


<td className="text-center">
<a className="btn btn-link" href="#" onClick={(e) => {e.preventDefault();alert("test");}}>
LinkCaption
</a>
<button onClick={() => alert("test!")}>
ButtonCaption
</button>
</td>


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


Games that require players to create, locate, or identify words using letters, clues, or categories are known as word games.



Hi,

Can you try delegated Event Handlers in Vanilla JS:


useEffect(() => {
const tableBody = document.querySelector("tbody");
if (tableBody) {
tableBody.addEventListener("click", (e) => {
if (e.target.matches(".btn-link")) {
e.preventDefault();
alert("test");
}
});
}

return () => {
if (tableBody) {
tableBody.removeEventListener("click", () => {});
}
};
}, []);


Please try the above. For native Next.js CRUD we would suggest you to wait out new product that we will release in the next week. We will provide full cycle CRUD solutions for next.js within Metronic UI style.

Regards,
Sean


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(