Skip to content
Advertisement

Datatable Action Custom Delete Confirmation not working

Actually am trying to implement custom actions buttons (In my case using a tag) in my datatable. here i want when user click on delete link then i want a confirm box saying “Are you sure” or something like that.

 public function dataTable($query)
    {
        $editUrl = route('signup.index');
        // <a class="btn btn-info waves-effect" href="'.$editUrl.'/{{$id}}/delete">Delete1</a>
        if(Auth::user()->hasRole('Super Admin'))
            return datatables()
                ->eloquent($query)
                ->addColumn('action', '<a class="btn btn-info waves-effect" href="'.$editUrl.'/{{$id}}/delete"  onclick="return confirm(1)">Delete</a>');
        else
            return datatables()
                ->eloquent($query);
        
    }

Now Here when i click on delete link then it is working fine But when i pass any string in confirm function then the confimation not working.

 public function dataTable($query)
    {
        $editUrl = route('signup.index');
        // <a class="btn btn-info waves-effect" href="'.$editUrl.'/{{$id}}/delete">Delete1</a>
        if(Auth::user()->hasRole('Super Admin'))
            return datatables()
                ->eloquent($query)
                ->addColumn('action', '<a class="btn btn-info waves-effect" href="'.$editUrl.'/{{$id}}/delete"  onclick="return confirm("Are you Sure")">Delete</a>') //This is not working; 
        else
            return datatables()
                ->eloquent($query);
        
    }

is there any other approach for this, thanx in advance.

Advertisement

Answer

You have a double quote " issue at onclick="return confirm("Are you Sure")". Just using another type of quote for the string then it will work as expected. Something like:

onclick="return confirm(`Are you Sure`)"
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement