douduan5753 2017-09-16 08:35
浏览 91
已采纳

Laravel:分页使用下拉菜单限制数字

I have a page which contain a table to display a list of users from the database and i used pagination to display only 10 users per page how i can change the number of users depend on the number selected by dropdown menu for example in the link below the second table contain "Show entries" which needed here. so can i pass the value from selected item to controller or there is a different way to do that ? https://adminlte.io/themes/AdminLTE/pages/tables/data.html

  • 写回答

2条回答 默认 最新

  • doumei8126 2017-09-16 08:51
    关注

    You will have to make a variable which will hold the pageinate data, suppose you are sending through ajax, use the pageinateData and in your controller you can call something like this:

    $users = App\User::paginate($request->pageinateData);
    

    So every time you can call with this data set.

    EDIT:

    In your controller you can do something like this:

    public function pUserList(Request $request) {
        $data = [];
        $data['users'] = App\User::orderBy('id', 'desc')->paginate($request->pageinateData);
    
    
        return view('userlist', $data);
    }
    

    $this will give you errors. You can use on change in jquery to get the values

    $(document).ready(function() {
      $('#issueinput5').on('change', function() {
        alert($('#issueinput5').val());
        $.ajax({
            url:'your url here',
            method:'POST',
            data:{'pageinateData':$('#issueinput5').val(),},
            success:function(d){
             // Do your code...
            }
       });
      });
    });
    

    Edit 2:

    For the csrf_token you need to do the following: add to your html headers

    <meta name="csrf-token" content="{{ csrf_token() }}">
    

    and in ajax call you need to have:

    $(document).ready(function() {
      $('#issueinput5').on('change', function() {
        $.ajax({
            url:'/lists/user',
            method:'POST',
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            data:{'pageinateData':$('#issueinput5').val(),},
            success:function(d){
              console.log(d)
            }
       });
      });
    });
    

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?