[英]I am trying to filter search a table that is paginated
It only retrieves data that is on the current page, not all the data in the database.How do i get it to filter through all the records and not only the records on the current page.I am using laravel for my backend and javascript for the filter search function.I have 10 records my table paginates at 5 records.I can filter search 5 records but not the entire 10.The rest of the records i can only filter when go to the second page 它只检索当前页面上的数据,而不是数据库中的所有数据。我如何获取它来过滤所有记录,而不仅是当前页面上的记录。我正在使用laravel作为后端,而javascript用于我有10条记录,我的表分页为5条记录。我可以过滤搜索5条记录,但不能过滤全部10条记录。其余记录我只能在转到第二页时进行过滤
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-12 col-md-offset-0">
<div class="panel panel-default">
<div class="form-group">
<div class="panel-heading">Admin Dashboard <a href ="/users/index" style="margin-left:50px">USERS</a></div>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">
<div class="panel-body">
@if (session('message'))
<div class="alert alert-success">
{{ session('message') }}
</div>
@endif
@if ($orders->count() == 0)
<p>No orders yet.</p>
@else
<div class="table-responsive">
<table class="table table-striped table-bordered" id="myTable">
<thead>
<tr>
<th>ID</th>
<th >Customer Name</th>
<th>Address</th>
<th>Phone</th>
<th>Delivery date</th>
<th>Type</th>
<th>Flavor</th>
<th>Frosting</th>
<th>How many</th>
<th>Price</th>
<th>Instructions</th>
<th>Status</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
@foreach ($orders as $order)
<tr>
<td>{{ $order->id }}</td>
<td>{{ $order->customer->name }}</td>
<td>{{ $order->address }}</td>
<td>{{ $order->phone }}</td>
<td>{{ $order->delivery }}</td>
<td>{{ $order->size }}</td>
<td>{{ $order->flavor }}</td>
<td>{{ $order->toppings }}</td>
<td>{{ $order->number }}</td>
<td>{{ $order->price }}</td>
<td style="max-width:200px"><textarea>{{ $order->instructions }}</textarea></td>
<td><a href="{{ route('admin.orders.edit', $order) }}">{{ $order->status->name }}</a></td>
<td><a href="{{ route('admin.orders.destroy', $order) }}"> <button class = "btn btn-danger btn-sm" >Delete</button></a></td>
</tr>
@endforeach
</tbody>
</table>
</div> <!-- end table-responsive -->
@endif
<div id="links"> {{$orders->links()}}</div>
</div>
</div>
</div>
</div>
</div>
<script src="../js/jquery-3.3.1.min.js"></script>
<script>
function myFunction() {
// Declare variables
var input, filter, table, tr, td,links, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
links=document.getElementById("links");
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
@endsection
You can't filter data the is not fetched from the beckend without making another API call. 如果不进行另一个API调用,则无法过滤未从beckend获取的数据。 You can either make another API call with the filter (and the pagenate the answer), or retrieve all the data from the server and make the pagination only for display porposes (not recommended at all)
您可以使用过滤器进行另一个API调用(然后对答案进行分页),或者从服务器检索所有数据并仅对显示目的进行分页(完全不建议使用)
将您的Javascript过滤器发布到存储在会话中的控制器中,在您的loadingController中检索该会话变量并在分页之前进行过滤
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.