Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

DropDown for datatables in Laravel version

I'm working on Metronic 8 -> Laravel version -> Demo1 (Latest update -> 12/01/2021) ,
I tried to add a dropdown action menu to the last column of the datatable, the button is there but it's not working (no dropdown items shows up on click).

this is the config for pages.php :

"agent" => array(
"title" => "Agents List",
"assets" => array(
"custom" => array(
"css" => array(
"js" => array(


this is the action_men blade file:

<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>

the datatable file :

public function dataTable($query)
return datatables()
->addColumn("action", "agent.action_menu");

public function html()
return $this->builder()
"buttons" => ["excel","pdf","print"],
->parameters(["scrollX" => true])
->addTableClass("align-middle table-row-dashed fs-6 gy-5");

routing is like this :
Route::resource('agent', App\Http\Controllers\AgentController::class);

this is what the console is showing :

and this is how the button looks like :

Thank you for the support

Text formatting options

Replies (11)


Please use the example dropdown here.

<td class="text-end">
<button type="button" class="btn btn-light-primary me-3" data-kt-menu-trigger="click" data-kt-menu-placement="bottom-end">
<!--begin::Menu 1-->
<div class="menu menu-sub menu-sub-dropdown w-300px w-md-325px" data-kt-menu="true" >
<div class="px-7 py-5">
<div class="fs-4 text-dark fw-bolder">Filter Options</div>

<div class="separator border-gray-200"></div>

<div class="px-7 py-5">

<!--end::Menu 1-->

In your data table class app/DataTables/*.php, please add this config in the parameters to init the dropdown.

"drawCallback" => "function() { KTMenu.createInstances(); }",


Thank you Faizal, it worked like a charm.
One more question of you don't mind please, I tried to implement sweet alert confirmation to the delete button in the action menu, but it's not calling the sweet alert confirmation, instead it's deleting the record without a confirmation.
Is there a right way to do that ?? Thank you

Your welcome happy

Any usage of the JS plugin within the data table has to be reinitialised. Because the elements inside the data table are dynamically added after the data table is loaded. Please try to add the SweetAlert function inside drawCallback similar to the dropdown.


One more question : why my account here in is marked as guest ? Though I purchased the theme earlier last year.

Hi happy

Please add your name to your profile page.


Thank You Faizal !
I'm still hustling with implementing SweetAlert delete confirmation in the action menu of the datatables.
If you could take some of your time to help me with it i'll be gratefull.


You could do something like this to use sweetalert with a clicked button.

$(document).on("click", ".delete-button", function (e) {
showCancelButton: true,
buttonsStyling: false,
}).then((result) => {
if (result.isConfirmed) {


I'm using the same code, and after many attempts of fixing it, the script is deleting without waiting for the user to confirm the deletion on the sweet alert message, I made a video if you want to check it out :
and this is my actual code :
The controller :

return redirect()->route("agent.index")->with("success","User deleted successfully");;

the form (in menu_action blade file of the datatable) :

<form method="post" action="{{ route("agent.destroy", $id) }}">
{{-- @method("delete") --}}
<input name="_method" type="hidden" value="DELETE">
<button type="submit" class="btn d-flex btn-active-light-primary" onclick="myFunction()">Delete</button>

and this is the route :

Route::resource("agent", App\Http\Controllers\AgentController::class);

the script after some tweaking (in the menu_action blade file) :

function myFunction()
title: "Are you sure?",
text: "You won"t be able to revert this!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, delete it!"
}).then((result) => {
if (result.isConfirmed) {
"Your file has been deleted.",

Thnk You Faizal for your help, I appreciate it. I managed to fix my issue.

Thank you again

Glad you have fixed the issue happy
Feel free to let us know if you need more help


I tried to reproduce the KTMenu calling but I couldn't as I can't find any variables called Ktmenu that links to the datatable buttons as the first issu.

My hired developer seems not mastering the theme, and according to his words: Metronic theme is a very good theme but it's so complicated happy

I'm trying my self to implement the function but no success, if you could give me a push that could be great Faizal.

Thank You

Text formatting options
Text formatting options