操作后如何在表格上保持相同的分页页面 [英] How to remain same pagination page on table after action

查看:92
本文介绍了操作后如何在表格上保持相同的分页页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个表(使用数据表),并在该表中执行了一些操作.在表中,我有一个按钮可以执行删除"功能,也可以使用数据表进行分页.例如,我在第5页,并且我想在单击删除"时删除一行,它刷新页面并返回到第1页.删除操作后如何将其保留在第5页?下面是我的表和控制器功能

i have created a table (using datatables) and in the table a few actions. in the table i have a button to do a function "delete", also using datatables i get pagination.. So for example i am at page 5, and i want to delete a row when i click delete it refreshes the page and goes back to page no 1. How can i make it remain at page 5 after the action delete? Below are my table and controller function

viewStatistics.blade:

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

推荐答案

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

There is an option named stateSave in jquery datatables. Please check the code below:

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

这篇关于操作后如何在表格上保持相同的分页页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆