实际上,我正在尝试使分页禁用处理程序,以便如果我停留在第一页上,则第一页和上一页将被禁用,而下一页和最后一页将保持可单击状态,以便可以转到下一页和最后一页。同样,如果我停留在最后一页上,则下一页和最后一页将被禁用,而上一页和第一页将仍然可以单击。这样我就可以转到上一页和第一页。如何管理该系统?
分页视图设计:
第一个按钮是第一页,第二个按钮是上一页,第三个按钮是分页号的输入区域,它是我要进入的页数,第四个按钮是下一页,第五个按钮是最后一页。
功能在这里:
public function index(){
$master_product_list = EbayMasterProduct::with('variationProducts')->orderByDesc('id')->paginate(50);
$master_decode_product_list = json_decode(json_encode($master_product_list));
return view('ebay.master_product.master_product_list',compact('master_product_list','master_decode_product_list'));
}
这是我的分页视图代码:
<div class="pagination-area">
<form action="{{url('pagination-all')}}" method="post">
@csrf
<div class="datatable-pages d-flex align-items-center">
<span class="displaying-num"> {{$master_product_list->total()}} items</span>
<span class="pagination-links d-flex">
<a class="first-page btn" href="{{$master_decode_product_list->first_page_url}}" data-toggle="tooltip" data-placement="top" title="First Page">
<span class="screen-reader-text d-none">First page</span>
<span aria-hidden="true">«</span>
</a>
<a class="prev-page btn" href="{{$master_decode_product_list->prev_page_url}}" data-toggle="tooltip" data-placement="top" title="Previous Page">
<span class="screen-reader-text d-none">Previous page</span>
<span aria-hidden="true">‹</span>
</a>
<span class="paging-input d-flex align-items-center">
<label for="current-page-selector" class="screen-reader-text d-none">Current Page</label>
<input class="current-page" id="current-page-selector" type="text" name="paged" value="{{$master_decode_product_list->current_page}}" size="3" aria-describedby="table-paging">
<span class="datatable-paging-text d-flex">of<span class="total-pages">{{$master_decode_product_list->last_page}}</span></span>
<input type="hidden" name="route_name" value="ebay-master-product-list">
</span>
<a class="next-page btn" href="{{$master_decode_product_list->next_page_url}}" data-toggle="tooltip" data-placement="top" title="Next Page">
<span class="screen-reader-text d-none">Next page</span>
<span aria-hidden="true">›</span>
</a>
<a class="last-page btn" href="{{$master_decode_product_list->last_page_url}}" data-toggle="tooltip" data-placement="top" title="Last Page">
<span class="screen-reader-text d-none">Last page</span>
<span aria-hidden="true">»</span>
</a>
</span>
</div>
</form>
</div>
您应该查看文档中可用的分页器方法。
https://laravel.com/docs/8.x/pagination#paginator-instance-methods
具体来说,您将需要以下这些:
$paginator->currentPage(); // get the current page number
$paginator->lastPage(); // get the page number of the last available page
如果要删除按钮,您的代码将如下所示:
<div class="pagination-area">
// ...
@if ($master_product_list->currentPage() > 1)
// first and previous buttons
@endif
// ...
@if ($master_product_list->currentPage() !== $master_product_list->lastPage())
// last and next buttons
@endif
// ...
</div>
如果只想禁用按钮,则可以添加一个disabled
类:
<a class="first-page btn {{ $master_product_list->currentPage() > 1 ? '' : 'disabled' }}">
// ...
</a>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句