In this case, I woiuld suggest expanding the partial to include the entire <table> element along with the pagination links, so that everything you need is returned from the asynchronous request.
Is it Possible to replace pagination after ajax search in Laravel Like replacing body content in atable
Guys i am working with a project.
i have view.blade which displays all record in tabular format.
i wrote the tbody portion as separate partial
This is my controller before search
public function index()
{
$loc=Location_details::orderBy('created_at','desc')->paginate(10);
return view('Location_details.view')->withloc($loc);
}
this is my Location_details.view
<thead >
<th >Location</th>
<th> Area</th>
<th>Booth</th>
<th>Action</th>
</thead>
<tbody id="results">
@include('Location_details.tbody')
</tbody>
</table>
<div class="text-center" id="p">
{!! $loc->Links(); !!}
</div>
This is my Location_details.tbody
@foreach($loc as $locs)
<tr>
<td>{{ $locs->ven_loc }}</td>
<td>{{ $locs->ven_area }}</td>
<td>{{ $locs->ven_booth }}</td>
<td>
{!! Form::open(['route'=>['Location_details.destroy',$locs->id], 'onsubmit' => 'return ConfirmDelete()','method'=>'Delete']) !!}
<a href="{{ route('Location_details.edit',$locs->id) }}" class="btn btn-info glyphicon glyphicon-edit"></a>
<button type="submit" class="btn btn-info glyphicon glyphicon-trash">
</button>
</td>
this is my ajax request
$('#location,#area,#booth').on('keyup',function(){
$.ajax({
type : 'get',
url : '{{URL::to('search_location_details')}}',
data:{
'location': $('#location').val(),
'area': $('#area').val(),
'booth': $('#booth').val()
},
success:function(data)
{
console.log(data);
$('#results').html(data);
}
This is my search_location_details function in controller
public function search_location_details( Request $request )
{
$loc = Location_details::where(function ($query) use ($request)
{
if (!empty($request->location)) {
$query->Where('ven_loc', 'LIKE', '%' . $request->location . '%');
}
if (!empty($request->area)) {
$query->Where('ven_area', 'LIKE', '%' . $request->area . '%');
}
if (!empty($request->booth)) {
$query->Where('ven_booth', 'LIKE', '%' . $request->booth . '%');
}
})->orderBy('created_at','desc')->get();
return view('Location_details.tbody', compact('loc'));
}
here after search the search result is passed to the ajax return and then it is passed to the . so it replaces the tbody portion with the search result.
But the pagination must change according to the search result. but it is not changed.
is it possible to replace the the below pagination also ???
<div class="text-center" id="p">
{!! $loc->Links(); !!}
</div>
when i search using jquery that pagination link remains there and it is not updated as per my returned results. my pagination must update based on the return result this is what i expect.
Kindly some one help please..!!
Please or to participate in this conversation.