Laravel AJAX和没有url的分页

时间:2017-12-23 06:26:34

标签: php ajax laravel pagination

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

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

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()}}    

1 个答案:

答案 0 :(得分:0)

使用带有ajax的数据表https://datatables.net/,这也是排序行的最佳方式..