0
顯示我使用的用戶列表yajra/laravel-datatables。filterColumn在yajra/laravel-datatables中不起作用
除了Datatable自己的搜索框來過濾結果,我有一個組合框可以根據用戶的級別對用戶進行過濾。
這是我的組合框:
<div class="form-group" id="levelFilterWrapper">
<label for="levelFilter">Userlevel :</label>
<select id="levelFilter" name="levelFilter" class="form-control">
<option value="all">All</option>
<option value="admin">admin</option>
<option value="user">user</option>
<option value="centerManager">centerAdmin</option>
</select>
</div>
,這是我的jQuery代碼:
var allUsersTable =
$('#allUsersTable').DataTable({
processing: true,
serverSide: true,
"bSort": false,
"responsive": true,
ajax: {
url : '{!! route('usersData') !!}',
data: function(d){
d.level = $('#levelFilter').val()
}
},
columns: [
{data: 'checkbox', name: 'checkbox', "width": "20px"},
{data: 'userPic', name: 'userPic', 'className': 'text-center'},
{data: 'email', name: 'email'},
{data: 'created_at', name: 'created_at'},
{data: 'level', name: 'level', 'className': 'text-center'},
{data: 'actions', name: 'actions', 'className': 'text-center'}
]
});
$('#levelFilter').change(function (e) {
allUsersTable.draw();
});
,這是我yajra數據表laravel代碼:通過levelFilter
組合框
$users = User::select(['user_id', 'name', 'family', 'email', 'created_at', 'level']);
$datatable = app('datatables')->of($users)
->filter(function ($query) use ($request) {
if (!empty($request->get('level')) and $request->get('level') != 'all') {
return $query->whereLevel($request->get('level'));
} else {
return $query;
}
})
->orderBy('created_at', 'desc')
->addColumn('checkbox', '<input type="checkbox" name="item_id[]" value="{{$user_id}}" id="Check_{{$user_id}}" class="minimal">')
->addColumn('userPic', function ($user) {
return '<img src="http://www.gravatar.com/avatar/' . md5($user->email) . '?d=mm&s=30" class="img-thumbnail img-responsive">';
})
->editColumn('email', function ($user) {
return '
' . $user->name . ' ' . $user->family . '
<div class="en-text"><a href="mailto:' . $user->email . '" target="_blank">' . $user->email . '</a></div>
';
})
->editColumn('created_at', function ($user) {
return JDF::jdate('l j F Y - G:i', $user->created_at);
})
->addColumn('actions', function ($user) {
return '
<a href="/admin/user/' . $user->user_id . '/edit" class="btn btn-primary btn-sm btn-flat fa fa-pencil-square-o" data-toggle="tooltip" data-placement="top" title="Edit And View"></a>
<a href="#" class="btn btn-danger btn-sm btn-flat fa fa-trash-o delItem" data-toggle="tooltip" data-placement="top" title="Delete" data-item-id="' . $user->user_id . '"></a>
';
});
if ($keyword = $request->get('search')['value']) {
$datatable->filterColumn('name', 'where', '=', "%$keyword%");
}
return $datatable->make(true);
濾波工作正常但我希望當管理員選擇一個用戶級別表單,通過DataTabl進行篩選在搜索框中搜索該選定的級別。但類型後搜索框中輸入一些字符,再次顯示了組合框過濾完全相同的結果,似乎搜索框篩選不會在這種情況下
如果級別加密的,因此如何在laravel使用此過濾器@ABDeveloper ? 我已經使用特徵加密Crypt來加密和解密 –