简体   繁体   中英

how to add a pagination inside tabs

Im new to laravel 5.2. I just want to ask how to add paginations inside tabs. In my interface there are 5 tabs and eack tab is displaying separate 5 tables from the database. And the database which i using is oracle. In my interface i have added paginatiins for the first tab and it worked successfully.(i added simplepagination method)

But when i adding same method to second tab pagination appeared and when i click the next button on that pagination it directed to the 2nd page of 1st tab not the 2nd page of second tab. I'll be really thankfull if some one can help me to solve this

Thank you

Assuming you're using the bootstrap tab panel, you can paginate each tab like this:

First, you don't need to change the code in your controller, and you can just use the default pagination function ->paginate(15);

But in the view, for the pagination links, you need to change the code to this:

{{ $balances->fragment('tab_id')->links() }}

The fragment('tab_id') part, changes the pagination URL to something like ..?page=1#tab_id

Then, when the page reloads to show different pages, you can do this to open the tab that you want:

$(document).ready(function(){

   var url = document.location.toString();
    if (url.match('#')) {
        $('.nav-tabs a[href="#' + url.split('#')[1] + '"]')[0].click();
    } 

    //To make sure that the page always goes to the top
    setTimeout(function () {
        window.scrollTo(0, 0);
    },200);

  });

I' assuming you are using Pagination

And you can do:

$allUser = User::paginate(2, ['*'], 'user');
$allRole = Role::paginate(2, ['*'], 'role');

return response()->json(array($allUser,$allRole));

Now you get something like:

[
  {
    "total": 17,
    "per_page": 2,
    "current_page": 1,
    "last_page": 9,
    "next_page_url": "http://urlsite/api/v1/user?user=2",
    "prev_page_url": null,
    "from": 1,
    "to": 2,
    "data": [
      {
        "id": 1,
        "role_id": 1,
        "username": "test",
        "first_name": "test",
        "last_name": "test",
        "email": "test@gmail.com"
      },
      {
        "id": 2,
        "role_id": 2,
        "username": "test2",
        "first_name": "test",
        "last_name": "test",
        "email": "test@hotmail.com"
      }
    ]
  },
  {
    "total": 4,
    "per_page": 2,
    "current_page": 1,
    "last_page": 2,
    "next_page_url": "http://urlsite/api/v1/user?role=2",
    "prev_page_url": null,
    "from": 1,
    "to": 2,
    "data": [
      {
        "id": 1,
        "name": "superuser"
      },
      {
        "id": 2,
        "name": "administrator"
      }
    ]
  }
]

i have solved this by using below methods thanks for the help

in my controller

public function index()

{
    $para_id=false;
    $data_para=Input::all();
    if($data_para){
        $para_id=$data_para['pagetype'];
    }
    $balances=DB::table('in_balances')->simplePaginate(5,['*'],'balances');
    $balances->setPath('/in-parameter/parameter?pagetype=1');
}
   return view('in-parameter.parameter',
           ['balances'=>$balances,
            'para_id'=>$para_id]);

in my blade.php Balance

{!! Form::open(array('url' => 'in-parameter/parameter', 'class' => 'form-inline', 'method' => 'post')) !!}

        -------------------------------------
        -------------------------------------
        ------------------------------------

{!! Form::close() !!}

          <div class="pagination"> {{ $balances->links() }} </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM