简体   繁体   English

我正在尝试过滤搜索已分页的表

[英]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.

相关问题 我正在尝试在反应中添加添加搜索过滤器,但我收到此错误 - I am trying to add add Search filter in react but I am getting this error AngularJS-搜索整个分页表 - AngularJS - Search on the entire paginated table 我在过滤搜索时做错了什么 - What am i Doing wrong in to filter search 我正在尝试明智地过滤数据类别 - I am trying filter data category wise 我正在尝试将模式按钮传递给 laravel 中的 ajax 搜索结果表 - I am trying to pass modal button to ajax search result table in laravel Vuejs / javascript / 我正在尝试连接一个搜索栏来搜索我的表格并根据我的输入显示结果 - Vuejs / javascript / I am trying to connect a search bar that searches my table and displays the results according to my input 我试图在画布中插入一张桌子 - i am trying to insert a table inside the canvas 我正在尝试使用递增的数字填充表 - I am trying to populate a table with a number that increments 我正在尝试将JavaScript中的filter:Brightness应用于一堆图像元素 - I am trying to apply filter:brightness in JavaScript to a bunch of image elements 如何使用reactJS创建过滤的搜索表。 试图让我的搜索栏过滤表中的信息 - How to create a filtered search table using reactJS. Trying to get my search bar to filter the info in the table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM