In my project I have installed jscroll:
npm i jscroll
And I have made the following js (myjs.js
):
$(document).ready(function(){
$('#scroll').jscroll({
loadingHtml: '<div class="customRow">' +
'<div class="deltaLabel w-100 d-flex justify-content-center"><i class="fa-solid fa-circle-notch fa-spin"></i></div>'+
'</div>',
nextSelector: 'a.jscroll-next:last',
contentSelector: 'div.customRow',
});
});
That is loaded upon this view (users.blade.js):
<div id="scroll" style="overflow-y: scroll; height: 58vh;">
@foreach($users as $user)
<div class="row">
{{$user->email}}
</div>
@endforeach
@if ($users->hasMorePages())
<a class="jscroll-next" href="{{ $users->nextPageUrl() }}"></a>
@endif
</div>
I also made a simple route:
Route::get('/users',function(Request $request){
$users = User::orderBy('id')->cursorPaginate(200);
return view('users',['versions'=>$users]);
});
But it seem kinda vague upon how cursorPaginate
takes the next cursor. Also in case I want to do some searching for example:
Route::get('/users',function(Request $request){
$email = $request->get('email',null)
$users = User::orderBy('id')
$users->where('email',$email)->cursorPaginate(200);
return view('users',['versions'=>$users]);
});
How my route will know the next page. Using SQL Server and trying this:
Route::get('/users',function(Request $request){
$cursor = $request->input('cursor', null);
$users = User::orderBy('id')->cursorPaginate(200,$cursor);
return view('users',['versions'=>$users]);
});
I get the following error in SQL Server:
Illuminate\Database\QueryException: SQLSTATE[42S22]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Invalid column name 'eyJpZCI6MjAwLCJfcG9pbnRzVG9OZXh0SXRlbXMiOnRydWV9'. (Connection: sqlsrv, SQL: select top 201 [eyJpZCI6MjAwLCJfcG9pbnRzVG9OZXh0SXRlbXMiOnRydWV9] from [users] where ([id] > 200) order by [id] asc) in file /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 822
Therefore how I can know what is the next cursor in my route and use that to fetch data?
But it seem kinda vague upon how cursorPaginate takes the next cursor. Also in case I want to do some searching for example:
It is not vague because you can provide the cursor paginator as:
Route::get('/users',function(Request $request){
$cursor = $request->input('cursor', null);
$users = User::orderBy('id')->cursorPaginate(200,['*'],'cursor',$cursor);
return view('users',['versions'=>$users]);
});
But still I don't know if searching does affect the result.