php - 操作后如何在表格上保持相同的分页页面

标签 php laravel datatable pagination datatables

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

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>

Controller :

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.'
  ]);
}

最佳答案

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

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

关于php - 操作后如何在表格上保持相同的分页页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34484275/

相关文章:

c# - 我如何构造一个 OleDbCommand 查询,以便我可以从一个 .MDB 中获取表,并将它们替换为另一个 .MDB

php - 如何在另一个查询中使用一个查询的结果(PHP/MySQL)

php - 使用选择选项 php 插入数据库信息

php - 如何在 codeigniter 中重置密码后重定向

javascript - 单击数据表中的按钮时执行操作

c# - 如何从数据集中删除数据表?

php - PHP 在 MySQL 上使用 SET 执行查询时出错

PHP Laravel Eloquent,foreach 破坏了我的关系

php - 如何在 laravel 的路由名称中传递变量?

laravel - 如何使用 AWS SNS 在 Laravel 中发送推送通知并在 Android 和 iOS 设备中使用默认声音?