If you wanted to persist the search filter across GET requests you might be better to append the search to the query string. Then the pagination links will automatically have the filter as well as the page number
Problem in pagination after ajax return in laravel
Guys I am working with a project milkfarm
I am having a form with search box and text box.
In the textbox event on change i wrote a jquery to search the value
Everything is file it searches and appends with the
But after search is done if I move to page 2 then it is refreshed the
search option disappears and all the data are displayed
Say for example I will seach time=”am” then it fetches 7 records
because there are only 7 record matches. But I have given
pagination(5). So only 5 records are displayed in the page 1 to see the
balance 2 records if I click page 2 the the page is refreshed so search
done is cancelled
How to rectify it
This is my view.blade
<tbody >
@foreach($exs as $ex)
<tr>
<td>{{ $ex->date }}</td>
<td>{{ $ex->time }}</td>
<td>{{ $ex->no_of_litre }}</td>
<td>{{ $ex->note }}</td>
</tr>
@endforeach
</tbody>
This is my javascript
<script type="text/javascript">
$('#search_time').on('keyup',function(){
$.ajax({
dataType: 'json',
type : 'get',
url : '{{URL::to('search_excess_milk_details')}}',
data:{
'search_time': $('#search_time').val()
},
success:function(data)
{
var res='';
$.each (data, function (key, value) {
res +=
'<tr>'+
'<td>'+value.date+'</td>'+
'<td>'+value.time+'</td>'+
'<td>'+value.no_of_litre+'</td>'+
'<td>'+value.note+'</td>'+
'</tr>';
});
$('tbody').html(res);
}
});
})
</script>
This is my controller search
public function search_excess_milk_details( Request $request )
{
$xcess_milks = Excess_milk::where(function ($query) use ($request)
{
if (!empty($request->search_time)) {
$query->Where('time', 'LIKE', '%' . $request->search_time . '%');
}
})->orderBy('date','asc')->get;
return Response($xcess_milks);
}
Kindly some one help please..!!!
Please or to participate in this conversation.