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
我有一个页面,其中包含一个表格,用于显示数据库中的用户列表,我使用分页仅显示 每页10个用户如何更改用户数量取决于下拉菜单中选择的数量,例如在第二个表格下方的链接中包含此处所需的“显示条目”。 那么我可以将所选项目中的值传递给控制器吗?或者有不同的方法可以做到这一点吗? https://adminlte.io/themes/AdminLTE/pages/tables/data.html p> div>
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.
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)
}
});
})
})