【问题标题】:How to remain same pagination page on table after action操作后如何在表格上保持相同的分页页面
【发布时间】:2018-05-04 15:05:40
【问题描述】:

我创建了一个表(使用数据表)并在表中执行了一些操作。在表中我有一个按钮来执行“删除”功能,也使用数据表我得到分页.. 例如我在第 5 页,当我点击删除时我想删除一行它刷新页面并返回到第 1 页。如何在删除操作后使其保留在第 5 页?下面是我的表格和控制器功能

viewStatistics.blade:

<table class="table table-hover demo-table-search table-responsive-block alt-table" id="tableWithSearch">
  <thead>
    <tr>
      <th class="text-center" style="width:80px;">ID</th>
      <th class="text-center">Date</th>
      <th class="text-center">Question <br> Asked</th>
      <th class="text-center">Low <br> Confidence</th>
      <th class="text-center">No <br> Answer</th>
      <th class="text-center">Missing <br> Intent</th>
      <th class="text-center">Webhook <br> Fail</th>
      <th class="text-center">Status</th>
      <th class="text-center">Action</th>
    </tr>
  </thead>
  <tbody>
    @foreach($data as $sessionID => $value)
      <tr>
        <td class="text-center">{{$value['identifier']}}</td>
        <td class="text-center">{{date("d M", strtotime($value['dateAccess']))}}</td>
        <td class="text-center">{{$value['total']}}</td> <!-- question asked -->
        <td class="text-center">{{$value['low confidence']}}</td> <!-- low confidence -->
        <td class="text-center">{{$value['no answer']}}</td> <!-- no answer -->
        <td class="text-center">{{$value['missing intent']}}</td> <!-- missing intent -->
        <td class="text-center">{{$value['webhook fail']}}</td> <!-- webhook fail -->
        <td class="text-center" style="{{$value['status'] == 'Reviewed' ? 'color:green' : 'color:red'}}">
          {{$value['status']}}
          @if($value['status'] == 'Pending')
            <input type="checkbox" name="check" class="check" value="{{$sessionID}}">
          @endif
        </td> <!-- status -->
        <td class="text-center">
          <div class="btn-group">
            <button type="button" class="btn alt-btn alt-btn-black dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Manage</button>
            <ul class="dropdown-menu">
              <li>
                <a href="{{action('AltHr\Chatbot\TrackerController@viewStatisticsLog', [$companyID, $sessionID, $value['status'], $value['identifier']])}}" class="btn btn-link">View</a>
              </li>
              <li>
                <a href="{{action('AltHr\Chatbot\TrackerController@deleteStatistics', [$companyID, $sessionID])}}" class="btn btn-link" onclick="return confirm('Are you sure that you want to delete this chat logs?')">Delete</a>
              </li>
              @if($value['status'] == 'Pending')
              <li>
                <a href="{{action('AltHr\Chatbot\TrackerController@updateStatisticsStatus', [$companyID, $sessionID])}}" class="btn btn-link">Mark as Done</a>
              </li>
              @endif
            </ul>
          </div>
        </td> <!-- action -->
      </tr>
    @endforeach
  </tbody>
</table>

控制器:

public function deleteStatistics($companyID, $sessionID)
{
  DiraChatLog::where('company_id', $companyID)->where('sessionID', $sessionID)->delete();
  return redirect(action('AltHr\Chatbot\TrackerController@viewStatistics', compact('companyID')))->with('notification',[
    'status' => 'success',
    'title' => 'Statistics Deleted',
    'message' => 'The Statistics have been deleted.'
  ]);
}

【问题讨论】:

    标签: php laravel datatable pagination datatables


    【解决方案1】:

    在 jquery 数据表中有一个名为 stateSave 的选项。请检查以下代码:

    $('#example').dataTable({ stateSave: true });
    

    【讨论】:

    • 嗨,因为我在 laravel 中这样做,我应该在刀片文件中使用此代码吗?
    • 可以,可以添加。
    • 谢谢它的工作。你也知道我是否可以在数据表中添加一个可以跳过页面的代码,例如 >skip 5 或 >skip 10?
    • 到目前为止,我猜数据表中没有可用的跳过页面选项。
    猜你喜欢
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多