Laravel AJAX和没有url的分页

问题描述 投票:0回答:1

我有表显示许多行,我正在使用分页和排序功能,我也使用ajax返回行数和其他ajax返回两个日期之间的行。

问题是如果我想对行进行排序,同时在两个日期之间显示一些行,这对我不起作用。因为使用ajax时没有url。

public function index()
{
    $checks = Checks::orderBy('id', 'asc')->get();
    $checks= Checks::sortable()->paginate(10);
    return view('home',compact('checks'));
}

public function showpage(Request $request)
{
    if($request->ajax())
    {
        $checks= Checks::orderBy('id', 'asc')->paginate($request->inputpage);
        return view('layouts.showcheks',compact('checks'));  
    }
}

public function getCheckReport(Request $request)
{ 
    if($request->ajax()){
        $New=$request->StartDate;
        $Old=$request->EndDate;
        $checks= Checks::whereBetween('postingdate',[$New,$Old])->sortable()->orderBy('postingdate', 'asc')->get();
        return view('layouts.showcheks',compact('checks')); 
    }
}

showchecks.blade.php

@foreach($checks as $indexKey => $check)
    <tr >
        <td>{{$check->details}}</td>
        <td>{{date('m/d/Y', strtotime($check->postingdate))}}</td>
        <td>{{$check->description}}</td>
    </tr> 
@endforeach 

主页:

<table class="table" id="postTable">
    <thead>
        <tr>
            <th>@sortablelink('details','Details')</th>
            <th>@sortablelink('postingdate','Date')</th>
            <th>@sortablelink('description','Description')</th>
        </tr>
        {{ csrf_field() }}
    </thead>
    <tbody>
    @foreach($checks as $indexKey => $check)
        <tr >
            <td>{{$check->details}}</td>
            <td>{{date('m/d/Y', strtotime($check->postingdate))}}</td>
            <td >{{$check->description}}</td>
        </tr>
    @endforeach
    </tbody>
</table>
{{$checks->appends(Request::input())->links()}}    
php ajax laravel pagination
1个回答
0
投票

使用数据表https://datatables.net/与ajax是最好的方式也可以排序行也..

© www.soinside.com 2019 - 2024. All rights reserved.