Want to implement pagination like a pro in your real-world app? 🚀
In this video, we break down pagination step-by-step using our Job Portal App (Next.js + MySQL + Drizzle + TypeScript) — not just code, but the complete logic you must understand before coding.
💡 You’ll learn:
How pagination actually works
The golden formula behind it
Real-world approach used in production apps
Step-by-step system design (5 steps)
🔥 This video is made on public demand, so don’t skip — this is where real devs level up.
👉 Next video: Full implementation + coding ------------------------------------------------------------------------------------ 🔗 Useful Playlists
⌛TIMELINE⏳ 0:00 Pagination in Job Portal App (Intro) 0:16 Public Demand 🚀 Why Pagination Matters 0:30 What is Pagination & How It Works 3:30 Support the Channel ❤️ 3:50 5 Steps to Implement Pagination 4:03 Step 1: Understand Data Flow 4:42 Step 2: Golden Formula Explained 🔥 8:20 Step 3: Backend Logic (Limit & Offset) 10:00 Step 4: Frontend Integration 12:20 Step 5: UI & UX Considerations 13:40 shadcn Pagination Component 14:02 Try It Yourself Challenge 💡 14:30 What’s Next (Part 2 Coding)
0:00 Introduction to Pagination and Video Overview
3:50 Core Concepts: URL as State, Limit, Offset, and Total Pages
8:00 Database Queries, Sliding Window Algorithm, and UI Implementation
14:00 Final Tips, Code Resources, and Call to Action
Hello what's up guys
Welcome back to the nextgest and MySQL page in the job portal application
and today is day number 94 for us
and the video I've made today
is exactly that in response
to public demand and this is basically complete now
It's done there was once a comment from you but
now it's been a long time since you've replied
Dude I thought this was gonna be a comment but hey turns out this video actually works
and that's your pagination
Yeah guys so finally you can see it clearly now
at the bottom we have this pagination
you can see it very clearly
and in today's video I'll explain everything about this
pagination and how you can
implement it in your Next js projec
The data you'receiving in
the application from the
database here totals 9 and
then 10 making the total 10
10 jobs are available with us so that's
why you can see them here now and also
It shows you the previous one and here it shows you the
next one so we've done this in such a way tha
It's just that you've always
seen this like
perfectly aligned
meaning we have the previous
button we have our current page
Here we have our 2 and then
we have a Next Ka button here
I'm currently on page
number 1 that's why
If you look closely at my previous one
The button's opacity has slightly decreased and even
if you click it as many times
as you want it won't work
If I'm currently on page
number 1 then there's one
more card left that will appear on our second page
at's why we'll use page number 2—basically the
sliding window algorithm
where I'll make every effor
I can show 3 numbers at a
time with the current page
always centered and then
we have this at the end: nex
So basically even if you do it once it'll still work even
if you do it twice it'll still work for you
If you proceed from here you'll still
end up on the second page somehow or other
and when you reach the
second page if you look
closely the next keyword you see is completely
We won't disable this if any user
clicks on it we won 't
apply any effect
Even if you clicked on it nothing would
happen and we've reduced
the opacity by 50%
Page 2 you can see we've already added the class
here by default the set
send provides you with this
you're probably realizing right
now that we have two pages
1 and then 2 and we're currently
on the second page right
so the island appears slightly darker to you
and the previous button that was slightly lower before
is not disabled but yes we have put a
I disabled the click event so
it became inactive which is why
it's now active for you so if you were on the previous one
If I click you'll see
these cards and let's say
now we have only one let'
s say we have only 9 cards
and scroll through each page
showing嵩 9 cards = retrieving
I do one thing I set an expiry date like this one here =
The expiry date I
'm canceling right
now — this post is already finished
— on our system right now the
total jobs that are actually active
are still valid
they will total
nine and if there are nine the
What happens on the second page
let me check once—just one refresh
so you can see it very clearly when you have
only one page I mean
when you have a total of 9
If you have 9 or fewer items we'll only
display one page and that means you won't
be able to click on the previous button
anymore nor will the next button be available
you can't even click so it's working for
someone else and if it's more than three
If the page is 1
2 3 then you
get3 4 5 or 2 3 4 then you get 3 5
4 5 6 are shown to you in such a
way that it's incredibly awesome
you'll have fun so guys let's jump
right into the video without any delay—this video
might be a bit long because
There's so much to explain here so let's
jump right into the video without any delay
Make sure to check out the previous video before
this one — if you haven't already please do so
So far my channel has been awesome but
if you haven't subscribed to the technical
one yet please do so and don't forget to like and share the video as well
so siddha chalte hain yaha pe kuch steps hai
jo hume follow karne hai
so first is the core concept
url as a state hum isme
The state hook in our React app
isn't being used for pagination
obviously we'relying solely on the
URL as our single source of truth
ruth and kuch aapko
wo isre kisi dikhaye dekha
top pe search react
hoga and page equal to 2
page equal to 2
page equal to 2 on your URL
this is all you need
defining everything
page number
what to display on the previous button
what to display on the next button clicking on the second page
clicking on the third page
The entire game is played right on that URL
this is why and this is why not
we'll use the full anchor tag
we'll use the link
Golden math formula
second step
before touching the database
we must
calculate three things
and those three things are entirely
based on this parameter
— just look here
Page count can be 1 2 3
or any number but first I
need to ask about the
limit for a particular page
I mean on this page how
many items or cards would
you like to display So I'd
like to show a total of 9
So right now we have a
total of 9 so we'll
have 9 for you second I need to ask about the offset
just as you are on page
1 when you go to page 2
to display items on page
2 you need the previously
ow many items need to be bypassed
how many items need to be skipped
so that I can display items on the second page
on the first page you've already seen it
so that's your offset
items to skip
if you look at the formula
this is very importa
So the offset formula is: your
current page minus 1 equals limit
This has already been explained
above Let's say our limit is 9
and if you want to
visit page number 2 how
many items would you
need to skip so we skip
e first 9 items kyu
It will become 2 so when you click on second your current page will
become 2 so that 2 minus 1
Your limit was how much 9
so 2 minus 1 will be 1
obviously 1 times 9 will be 9
en when you go to
the second page you'
ll skip the initial 9 items or 9 cards
The next nine items
are shown to you
and then calculate the
total number of pages
now find out the total pages
It's much easier once
you first determine
how many pages you have in total
exist in total the total
number of pages is exactly that
— you'll only know once you know your own
You have data
your jobs table
how many rows are there in total
what is the total count just once if you could provide the total count
The engine stalled let's say I
have a total of 20 jobs on my end
then whatever limit we have you'll need to adjust accordingly
We'll divide it so the total
count divided by
the limit gives
your total page number for
example if it's 9 then it's 18
en 27 then 36 you get it
exactly 1 2 3 4
but if you have
If you have 20 job cards then
the mallab 20 jobs records
are in your possession and
when you divide them by 9
yeah it looks like 2.22 to you
now 2.22 how exactly are you seeing it
You'll show it in page format meaning will
you show 2 pages and
what exactly will you do
you'll see meaning two and a half pages
displayed so the basic
rule here is that if 0.1
It's already here even 0.01 or 0.1 if it arrives today then
you'll have to
print an extra page meaning
Here's what happened: 2
point something whatever occurred now
we'll use the math syllabus method
Two points whatever it is
just add it it'll become
three after the next number so if we round it up
en you'll need to display a total of 3 pages
these 3 things are required
limit offset
and then your
otal pages but first you need to
determine the total count query to be made
padega iske liye to aapko yeh 3 chizhe
If you keep going you'll eventually figure out these three things
then you'll know basically
Now I get it—what exactly
does limit mean and what
does offset mean I need the total number of pages
I need to find the total count okay
now here
this is the database engine
handling Diesel ORM's work here 2 queries
Imagine this: if real pagination
were used it would require
two trips meaning two full loops through your database
Marta has two trips 2 trips are what Marta
has now you'll find out why Marta has two trips
first of all this is the limit
and offset whenever you
fetch any data like this part
here whenever anyone comes
now they'll be on find job
Clicking does nothing
here—here's what happens
brother—if I apply pagination or a limit—
wouldn't be added so let's say I have a
total of 20 cards right then I would have
Twenty to twenty they just appear right
here — you know what I mean don't you
Twenty cards used to appear here
but now we're only seeing nine cards
—how did that become possible Because
we didn't even run the query yet
It's been decided yes brother
we're setting a limit now
—total 9 and we're also applying an offset right here
This is specifically about these two trips For
the first trip you won't need to set a limit
so now you only see 9 basically only 9 cards are dealt
and then you play this first
second trip will be taken nex
To find the total
count the total number
of your jobs is to put
it simply the total
How many active counts there are you'll still find out soon
that's the third point
you'll soon realize that real pagination
is spinning in circles one of which is this
To determine the
total count note that
apply the exact same filters such as search
or job type and expiration check
to both queries so your page must
stays yeh kya hai I'll explain it in code but
now you've also grasped the
concept then the UI building
and the sliding window what this
is is extremely important because
understanding it is absolutely
essential and grasp this point firmly
There's also a sliding
window algorithm and once you
understand it you'll get it—just imagine it this way
f we have 100 pages
you don't want
to render 100
buttons right here
what's being said is that if you have
100 pages then now you have 100 out of 100
f you show just a few buttons instead
create a sliding window of up
to 3 page numbers what happens
I'll tell you something suppose you'
ve calculated the total count and you
It turned out that brother needs 100 pages
from us so how many pages in total do you need
You're lagging behind you have 100 pages
when you have 100
pages you can do it too
You won't do it not 1 2 3 4
dot not 90 900
not this much
Just a little bit no dots just
a number that's all—we're doing
sliding window what are we
doing We'll have a previous one
What should we do now like 1
2 3 and then
we have our next
suppose our
current page is 4
then what should
we do inside this
3 4 and then 5 you
understand meaning what will
we do if my current page
is equal to 4 then my
The starting page will be
the current page minus 1
and the ending page will
be the current page plus 1
You're getting it meaning I'll show you 3 at a time and for my
current page I'
ll try to make sure we keep
center shown this way is your sliding window
giving you knowledge in
this manner so here I am
at's the one being referred to for example
your 4 5 6 previous and then next
to this is your something
you'll realize that
your starting page is the
current page minus 1 obviously if it's 4 the
I need 3 and your end page should be current
page plus 1 or else total
page and that's your
current page plus 1 to edge case
something like that if you're on the
page 1 force the window to show 1 2
and then 3 if you are on page
number 1 I'll force them to show you
1 2 3 if you're on the
last page shift the window
back you'll figure it out
and finally this is yours
e secret sauce the preserving filters
what are you saying that
look for example if a user clicks on page
number 2
You must not lose their active
search filters I feel like saying
if you're already here like you'
ve already come all the way here
likha to I showed you this now the thing
is that I only have 10 cards left mine
Pass there are only ten cards total so page 2 can't
be considered new because
it's already been shown to me
Only three remain here but
if say there were a lot more research I mean
job cards
If you click the second page the search you just
performed will only appear
when you click the second page
You should stay right here not go
searching around like you did here
moved to the second page where 9 cards appeared
along with whatever search you had conducted
Whatever filter you used has disappeared which shouldn't
have happened—this is exactly
the issue we're seeing here
always rebuild the URL using search
params to combine
existing filters the
new page number and this code so now
you can comfortably use const params
equal to new search parameters parameters
dot set in this manner what are you
actually doing here existing parameters
The route is set it will arrive at the parameters page
you're setting extra and it will be here
You're passing it off fine but right
now it feels way too small guys
If you handle it this way your pagination
is confirmed and for pagination purposes
So what should we use here By the way we're using a set of
pagination so guys you can see
that the pagination we've used
you can see it
very clearly here
look at the view code everything
Here's your item pagination
content —
everything you need is
right here alright guys
We work on it and today we'll wrap up this video
here I hope that the steps I'm about to show you now will be helpful to you
I'll share everything here all the code is
completely free I've
already updated it GitHub
Hey don't worry it's fine—just pick it up from there
and I'll specifically share this too I'll
explain it to you in the readme md file
It will happen and you try
whether you in so many steps have shared
with you after this
You can create it yourself or I'll even show
you that as for this
pagination we're discussing
Just try once don't worry I'll be back
tomorrow not going anywhere at four o'cloc
I'll be there soon but please try to
ease the pressure in your mind a little
Hey every time you're about to
code just say "ta " I'll handle
it—what should I do now You're stressed but I know that stress
You must come only then will you move
forward you must try whoever it may be
It's gone so please comment to let me know
and if you like the video please like and share with friends thanks
If you haven't subscribed to the channel yet please do so now
See you in the next video until then thanks so much guys
Stay safe