【问题标题】:Laravel AJAX and pagination with no urlLaravel AJAX 和没有 url 的分页
【发布时间】:2018-06-05 15:03:24
【问题描述】:

我有一个显示许多行的表格,我正在使用分页和排序功能,我还使用 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()}}    

【问题讨论】:

  • 使用数据表代替普通表。 inbuid 那里的功能。在行内进行所有比较
  • 你传递 URL 的部分在哪里?

标签: php ajax laravel pagination


【解决方案1】:

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

【讨论】:

  • 数据表与我的 css 设计冲突
  • 尝试添加第一个数据表 csss 然后添加您自己的 csss
猜你喜欢
  • 1970-01-01
  • 2015-02-01
  • 2014-09-12
  • 2016-11-30
  • 2016-01-05
  • 1970-01-01
  • 1970-01-01
  • 2018-08-17
  • 2015-11-27
相关资源
最近更新 更多