Get 2024 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $9
Get for 99$

KTDataTable not defined


I am trying to use datatables at metronic 9 and i am getting the following error, i have been trying for 1 week and there is no way to use it.  I am using Laravel 11 with vite, no front end frameworks.

ReferenceError: KTDataTable is not defined
at HTMLDocument.<anonymous> (users:372:31)


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (11)


Hi,

You can try to import /metronic-tailwind-html/dist/assets/js/core.bundle.js file into your Laravel from metronic-tailwind-html folder. This file is a bundle js file which you don't need to rebuild.

Hopefully, this will fix the issue ReferenceError: KTDataTable is not defined


Thank you



Hi! Thank you in advance. It works, but the styles are not working fine. the loading stills appearing top left without spin..



Hi,

If you still need assistance with this can you please provide a test link to your app via a private reply? We need to check the issue of missing styles.

Regards.



Hi Jordi segura

This is for Metronic v9.

Could you please check the browser console log if there any JS error?

Backend service is required when you use Remote Data Source.

Can you please send your datatable configuration?

Thank you



Hi of course,

the backend is:


public function getUsers(Request $request)
{
// Obtener los usuarios (esto puede variar dependiendo de c&oacute;mo obtienes los datos)
$users = UserService::getAllUsers();

// Estructurar la respuesta
$response = [
"page" => 1,
"pageCount" => 2,
"sortField" => null,
"sortOrder" => null,
"totalCount" => $users->count(),
"data" => $users->map(function ($user) {
return [
"id" => $user->id,
"name" => $user->name,
"email" => $user->email,
];
})
];

return response()->json($response);
}



The keenthemes textarea give me an error putting the js code, but it is this example but with the id, name and email fields:

" Remote data source"

https://keenthemes.com/metronic/tailwind/docs/components/datatable



I tested to change the index.ts like u sent to me and i didnt need to import the core.bundle.js anymore. but i still get the same problems. it is like i missed something. In order to get all working, should i install by npm some datatable library or something like that? it is like the js is not at all..


Deleted comment

Hi Jordi segura

Have you copy metronic-tailwind-html/src folder into your Laravel as stated in the documentation?

Please check this also if you got the related JS error.
https://github.com/keenthemes/metronic-tailwind-html-integration/issues/4

Thank you



Hi, yes, i am using metronic 9.0.1, not the 8.2.6, it is right ?



I finally achieved the datatable importing this to the app.blade.php:

<script src="{{ asset('assets/js/core.bundle.js') }}"></script>
i do not know why...

But it not works properly. The order is not working, the table show all the results without looking for the "show 5 per page", the next and back buttons not working...



it only happens to me with the Remote Data Source, with the static works fine


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(