douduan5753
douduan5753
2017-09-16 08:35
浏览 48

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
    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.

    点赞 评论
  • drap5081683
    drap5081683 2017-09-16 09:20

    You can try to do this

     $(document).ready(function(){
        $('#issueinput5').on('change',function(){
           $.ajax({
            url:'supply your url here',
            method:'POST',
            data:{'priority':$(this).val(),},
            success:function(d){
              console.log(d)
            }
           });
          })
        })
    
    点赞 评论

相关推荐