Animate my <tr> when deleting a row in a table - php

I'm migrating a table managed by JQuery to VueJS ( 2.4.4 )
I would like to add a small fade out + slide transition so the user understand the row has been deleted.
Here is my table:
<div class="container-fluid">
<table class="table table-togglable table-hover">
<thead>
<tr>
<th data-toggle="true">Name</th>
<th class="text-center" data-hide="phone">Federation</th>
</tr>
</thead>
<tbody>
#foreach($associations as $association) // This is Laravel blade
<association-item
:association="{{ json_encode($association) }}"
:url_edit="{{ json_encode(route('associations.edit', $association)) }}"
:url_delete="{{ json_encode(route('api.associations.delete', $association)) }}"
>
</association-item>
#endforeach
</tbody>
</table>
</div>
and inside my component template, <association-item> is:
<template>
<tr>
<td>
{{ association.name }}
</td>
<td align="center">
<button type="submit" class="btn text-warning-600 btn-flat" #click="deleteItem(association.id)">
<i :class=spinnerOrIcon></i></button></td>
</tr>
</template>
I tried this:
<template>
<transition name="fade" mode="out-in">
<tr>...</tr>
</transition>
</template>
with
<style>
.fade-enter-active,
.fade-leave-active {
transition: opacity 1s
}
.fade-enter,
.fade-leave-to {
opacity: 0
}
</style>
but it is not working. Why???

Related

Laravel On click Event Button [Enable button after upload file]

I have a table which contain two buttons, one is for uploading a file and the other one is for giving score. What I want to do is to give a condition for the second button which is the scoring button, whereby it can't be clicked (disabled) if there is no file uploaded. How can I achieve this?
Here is what my table looks like:
And here is my AdminController for the table
public function showpekerjaanppk(){
if(Auth::user()->status=='super'){
$pekerjaan = Pekerjaan::with('penyedia','user')->paginate();
return view('admin.showpekerjaan', compact('pekerjaan'));
}else{
$pekerjaan = Auth::user()->pekerjaans;
return view('admin.showpekerjaan', compact('pekerjaan'));
}
//return view('admin.showpekerjaan', compact('penyedia','pekerjaan','totalAvg'));
}
And here is my blade file for the table
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
#if (Auth::user()->status=='super')
<h3 class="card-title"><b>{{$penyedia->nama}}</b></h3> <br>
<h3 class="card-title">Nilai Total: <b>{{$totalAvg}}</b></h3>
#else
<h3 class="card-title"><b></b></h3> <br>
<h3 class="card-title"></b></h3>
#endif
<!-- /.card-header -->
<div class="card-body table-responsive">
<table id="tabelpekerjaan" class="table table-bordered">
<thead>
<tr>
<th style="width: 10px" rowspan="2">No.</th>
<th rowspan="2">Tanggal</th>
<th rowspan="2">Paket Pekerjaan</th>
<th rowspan="2">Nama Perusahaan</th>
<th rowspan="2">Lokasi Pekerjaan</th>
<th rowspan="2">PPK</th>
<th rowspan="2">Nilai Kontrak</th>
<th rowspan="2">Nilai</th>
<th rowspan="2">BAHP</th>
<th colspan="2">Aksi</th>
</tr>
<tr>
<td>BAHP</td>
<td>Nilai</td>
</tr>
</thead>
<tbody>
#php $no = 1; /*$totalNilai = 0.0;*/ #endphp
#foreach ($pekerjaan as $pekerjaans)
<tr>
<td>{{$no++}}</td>
<td>{{$pekerjaans->tanggal}}</td>
<td>{{$pekerjaans->pekerjaan}}</td>
<td>{{$pekerjaans->penyedia->nama}}</td>
<td>{{$pekerjaans->lokasi}}</td>
<td>{{$pekerjaans->user->name}}</td>
<td>Rp. {{number_format($pekerjaans->nilai_kontrak,0,',',',')}}</td>
#php
$pekerjaans->nilai_total = $pekerjaans->nilai_1 + $pekerjaans->nilai_2 + $pekerjaans->nilai_3 + $pekerjaans->nilai_4;
#endphp
<td>{{$pekerjaans->nilai_total}}</td>
<td>{{$pekerjaans->bahp}}</td>
<td>
Upload
</td>
<td>
Penilaian //disabled untill file uploaded
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
#if (Auth::user()->status=='super')
<div class="card-footer">
Kembali
</div>
#endif
</div>
</section>
Thank you in advance.
#if(isset($pekerjaans->yourFileCulmnName))
<td>
Penilaian //disabled untill file uploaded
</td>
#endif

hidden division is not appearing after operating click event for dynamic table

I am fetching data to a table from mysql database using php and jquery. But I want to keep the "details" column hidden, which I want should be slide down(appear ) in the corresponding table row after clicking a button named "show details". The following Image may clear my thought:
The jquery Code I am using for slide down is :
$(document).ready(function(){
$("#get_details").click(function(){
$("#get_details_button").slideToggle("slow");
});
});
The code I am using to fetch data is :
$sub_array = array();
$sub_array[] = $row["id"];
$sub_array[] = $row["product_name"].'<p id="get_details">'.$row["details"].'</p>';
$sub_array[] = '<button type="button" name="get_details_button" id="get_details_button" class="btn btn-success btn-xs get_details_button">Get Details</button>';
$data[] = $sub_array;
}
Please feel free to ask for any additional code if you need.
the html part is here :
<table id="user_data" class="table table-bordered table-striped">
<thead>
<tr>
<th width="30%">Image</th>
<th width="50%">Product Name</th>
<th width="20%">get Details</th>
</tr>
</thead>
</table>
You need to use class for p tag then whenever button is clicked use $(this).closest('tr').find(".get_details") to get p tag and show/hide same
Demo Code :
$(document).ready(function() {
//onclick of button
$(".get_details_button").click(function() {
//get p tag and show/hide it
$(this).closest('tr').find(".get_details").slideToggle("slow");
});
});
.get_details {
display: none
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="user_data" class="table table-bordered table-striped">
<thead>
<tr>
<th width="30%">Image</th>
<th width="50%">Product Name</th>
<th width="20%">get Details</th>
</tr>
</thead>
<tr>
<td>1
</td>
<td>Soemthig,,
<!--use class-->
<p class="get_details">Soemthing.....</p>
</td>
<td><button type="button" name="get_details_button" class="btn btn-success btn-xs get_details_button">Get Details</button>
</td>
</tr>
<tr>
<td>2
</td>
<td>Soemthig,,2
<p class="get_details">Soemthing2.....</p>
</td>
<td><button type="button" name="get_details_button" class="btn btn-success btn-xs get_details_button">Get Details</button>
</td>
</tr>
</table>
You don't need any ids to make this work. I don't know your markup but here is an example. You will need to work it out for your markup.
<div class="container">
<table>
<tr>
<td>{{ id }}</td>
<td>{{ product_name }}</td>
<td><button>details</button></td>
</tr>
</table>
<div class="product-details" style="display:none">...</div>
</div>
<div class="container">
<table>
<tr>
<td>{{ id }}</td>
<td>{{ product_name }}</td>
<td><button>details</button></td>
</tr>
</table>
<div class="product-details" style="display:none">...</div>
</div>
<div class="container">
<table>
<tr>
<td>{{ id }}</td>
<td>{{ product_name }}</td>
<td><button>details</button></td>
</tr>
</table>
<div class="product-details" style="display:none">...</div>
</div>
jquery
$('.container').find('button').on('click', function(e) {
e.preventDefault();
$(this).parent().parent().parent().parent().find('.product-details').slideToggle();
});

POST method of <form> is not working inside #foreach on blade file in laravel 5.6

Button doesnot work after using form inside #foreach. Any suggestion about how to use form inside a #foreach loop ?
is it even possible to use form inside a loop in laravel blade file?
here is my code of my laravel blade file. I have used form inside foreach for getting data of Book Amount. Any Suggestion about how to solve this problem?
#extends('layouts.app')
#section('content')
<div class="container">
<h1>Items On Cart:</h4>
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-body">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<table style="border-collapse: collapse;width: 100%;">
<tr style="border: 1px solid #dddddd;text-align: left;padding: 8px;font-size:20px;color: gray">
<th>Book Name</th>
<th>Author Name</th>
<th>Book Amount</th>
<th>Price</th>
<th>Action</th>
<th>Action</th>
</tr>
#foreach($cart_items as $data)
<form action="{{ route('change_item_amount',[$cart_info->id,$data->book_id]) }}" method="POST">
<tr>
<th>{{ show_books_name($data->book_id) }}</th>
<th>{{ show_books_author($data->book_id) }}</th>
<th><input type="number" name="amount" id="amount" value="{{ $data->item_amount }}"></th>
<th>{{ $data->price }} tk</th>
<th><button type="submit" class="btn btn-success">Change</button></th>
<th><a class="btn btn-success" href="{{ route('delete_book',[$cart_info->id,$data->book_id] ) }}">Delete</a></th>
</form>
#endforeach
</table>
</div>
<h2 style="padding-left:865px">Total = {{ $cart_info->total_price }} tk</h2>
</div>
</form>
</div>
</div>
</div>
#endsection
The simplest solution can be: place a form tag into a td, (btw it should be td, not th, you use th in thead):
<table style="border-collapse: collapse;width: 100%;">
<tr style="border: 1px solid #dddddd;text-align: left;padding: 8px;font-size:20px;color: gray">
<th>Book Name</th>
<th>Author Name</th>
<th>Book Amount</th>
<th>Price</th>
<th>Action</th>
<th>Action</th>
</tr>
#foreach($cart_items as $data)
<tr>
<td>{{ show_books_name($data->book_id) }}</td>
<td>{{ show_books_author($data->book_id) }}</td>
<td> <!-- Here we have empty td now --> </td>
<td>{{ $data->price }} tk</td>
<td>
<!-- Form is here now -->
<form action="{{ route('change_item_amount',[$cart_info->id,$data->book_id]) }}" method="POST">
<input type="number" name="amount" id="amount" value="{{ $data->item_amount }}">
<button type="submit" class="btn btn-success">Change</button>
</form>
</td>
<td><a class="btn btn-success" href="{{ route('delete_book',[$cart_info->id,$data->book_id] ) }}">Delete</a></td>
#endforeach
</table>

Update multiple rows in the index view Laravel

I am a beginner in laravel and I am trying to update all the records in the index view without having to enter to a different view to edit each item.
The idea is to click a button, and when I click on it the input data is enable to change the quantity of all data that is show in the index; and then have a submit button to update all the records.
At the moment when I click on the button it only enable the inputs of the first row, how can i do to enable all of them?
And how can I make a function in the controller to update all the records in my datatable at once, only clicking on a submit button??
I dont really know how to edit nd update the data in the same index page!!!
PLEASE HELP ME.
This is the default index view
This is what happens when i click the "Editar cantidades" button
View
#extends ('layouts.admin')
#section ('contenido')
<div class="panel-heading">
<h4>
Crear nuevo consumible
Listado de consumibles
</h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-9">
#include('inventlab.consumibles.search')
</div>
<div class="col-md-3">
<a id="enablebutton" class="pull-right btn btn-default" >Editar cantidades</a>
</div>
</div>
<table class="table table-hover nowrap" id="example" width="100%">
<thead class="thead-default">
<tr>
<th>Opciones</th>
<th>Nombre</th>
<th style="text-align: center">Sin abrir</th>
<th style="text-align: center">En uso</th>
<th style="text-align: center">Cantidad total</th>
</tr>
</thead>
#foreach ($consumibles as $cons)
<tbody>
<tr>
<td>
<i class="icmn-pencil5"> </i>
<i class="icmn-bin"> </i>
</td>
<td>{{ $cons->nom_cons }}</td>
<td style="text-align: center">
<input type='number' name='cant_sinabrir' id="sinabrir" value='{{ $cons->cant_sinabrir }}' disabled style="text-align: center;width: 3em;" min="0" />
</td>
<td style="text-align: center">
<input type='number' name='cant_enuso' id="enuso" value='{{ $cons->cant_enuso }}' disabled style="text-align: center;width: 3em;" min="0" />
</td>
<td style="text-align: center">
<input type='number' name='cant_total' id='total' value='{{ $cons->cant_total }}' disabled disabled style="text-align: center;width: 3em;" min="0" />
</td>
</tr>
<script type="text/javascript">
$(document).ready(function(){
$('#enablebutton').click(function(){
$('#sinabrir').removeAttr('disabled').focus();
$('#enuso').removeAttr('disabled').focus();
});
});
</script>
#include('inventlab.consumibles.modal')
#endforeach
</tbody>
</table>
</div>
#endsection
Controller
My index controller is ok, but I don't know how to make the update function run through all the records in the database and save the new values.
public function index(Request $request)
{
if ($request){
$query=trim($request->get('searchText'));
$consumibles=DB::table('consumibles')
->where('nom_cons','LIKE','%'.$query.'%')
->orwhere('alerta','LIKE','%'.$query.'%')
->orderBy('nom_cons','asc')
->get();
return view('inventlab.consumibles.index',["consumibles"=>$consumibles,"searchText"=>$query]);
}
}//End function index
public function update(ConsumibleFormRequest $request)
{
$data = $request->all();
$validate = $this->validateRegister($data);
if($validate['code'] == 200)
{
$register = $validate['data'];
$holder = Consumible::find($id);
$holder->update($register);
return Redirect::to('inventlab/consumibles');
}
else
{
return("No se pudo actualizar el registro");
}
return "Registro actualizado";
}//End function update
My current update function works when I have a different view and edit one per one record.

How to remain same pagination page on table after action

i have created a table (using datatables) and in the table a few actions. in the table i have a button to do a function "delete", also using datatables i get pagination.. So for example i am at page 5, and i want to delete a row when i click delete it refreshes the page and goes back to page no 1. How can i make it remain at page 5 after the action delete? Below are my table and controller function
viewStatistics.blade:
<table class="table table-hover demo-table-search table-responsive-block alt-table" id="tableWithSearch">
<thead>
<tr>
<th class="text-center" style="width:80px;">ID</th>
<th class="text-center">Date</th>
<th class="text-center">Question <br> Asked</th>
<th class="text-center">Low <br> Confidence</th>
<th class="text-center">No <br> Answer</th>
<th class="text-center">Missing <br> Intent</th>
<th class="text-center">Webhook <br> Fail</th>
<th class="text-center">Status</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
#foreach($data as $sessionID => $value)
<tr>
<td class="text-center">{{$value['identifier']}}</td>
<td class="text-center">{{date("d M", strtotime($value['dateAccess']))}}</td>
<td class="text-center">{{$value['total']}}</td> <!-- question asked -->
<td class="text-center">{{$value['low confidence']}}</td> <!-- low confidence -->
<td class="text-center">{{$value['no answer']}}</td> <!-- no answer -->
<td class="text-center">{{$value['missing intent']}}</td> <!-- missing intent -->
<td class="text-center">{{$value['webhook fail']}}</td> <!-- webhook fail -->
<td class="text-center" style="{{$value['status'] == 'Reviewed' ? 'color:green' : 'color:red'}}">
{{$value['status']}}
#if($value['status'] == 'Pending')
<input type="checkbox" name="check" class="check" value="{{$sessionID}}">
#endif
</td> <!-- status -->
<td class="text-center">
<div class="btn-group">
<button type="button" class="btn alt-btn alt-btn-black dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Manage</button>
<ul class="dropdown-menu">
<li>
View
</li>
<li>
Delete
</li>
#if($value['status'] == 'Pending')
<li>
Mark as Done
</li>
#endif
</ul>
</div>
</td> <!-- action -->
</tr>
#endforeach
</tbody>
</table>
Controller:
public function deleteStatistics($companyID, $sessionID)
{
DiraChatLog::where('company_id', $companyID)->where('sessionID', $sessionID)->delete();
return redirect(action('AltHr\Chatbot\TrackerController#viewStatistics', compact('companyID')))->with('notification',[
'status' => 'success',
'title' => 'Statistics Deleted',
'message' => 'The Statistics have been deleted.'
]);
}
There is an option named stateSave in jquery datatables. Please check the code below:
$('#example').dataTable({ stateSave: true });

Categories