WEBVTT

00:03.820 --> 00:05.260
Hey, did everyone share?

00:05.260 --> 00:10.900
And in this video, we're going to work with the where clause of the pagination or the fine method.

00:10.930 --> 00:16.630
Now, usually I never, ever create a method or a separate class or an instance for the pagination because

00:16.630 --> 00:19.060
it is really too simple to work on with that.

00:19.090 --> 00:22.690
All you got to do is use two method that is just limit and skip.

00:22.720 --> 00:29.020
Limit is how much values you want to show in a page itself or add the one request and skip is how many

00:29.020 --> 00:30.150
values you want to skip it.

00:30.160 --> 00:31.480
So this is all what it got.

00:31.480 --> 00:36.850
So here it is, the documentation which says aggregate prototype limit, maximum number of records to

00:36.850 --> 00:38.620
pass on to the next stage.

00:38.620 --> 00:42.610
And then we have got another one which is kid that how many records you want to skip.

00:42.610 --> 00:46.810
So for example, you want to show, let's just say five products on the page one.

00:46.810 --> 00:52.000
So obviously this time your limit is just five and your page is number one on the page.

00:52.000 --> 00:57.040
Number two, you want to skip the first initial five product and want to move to the next five products.

00:57.040 --> 00:58.090
That's really simple.

00:58.090 --> 01:00.700
So we don't use any kind of methods for that.

01:00.700 --> 01:06.190
But since we are writing this entirety of the WHERE clause, let's go ahead and work on with that.

01:06.190 --> 01:09.300
So in this case, just below the search, wherever you like.

01:09.310 --> 01:11.470
So let's just go here into this one.

01:11.470 --> 01:12.700
Let's create a simple method.

01:12.700 --> 01:13.830
Let's call this one s page.

01:14.200 --> 01:17.950
Now, page one absolute requirement is it needs to give me that.

01:17.950 --> 01:20.170
How many page you want to show per page.

01:20.170 --> 01:21.990
It's not going to magically know.

01:21.990 --> 01:22.180
No.

01:22.240 --> 01:26.290
That so we're going to go ahead and say result per page.

01:26.290 --> 01:27.610
So you have to give me that.

01:27.820 --> 01:34.630
Now I'm going to assume that let the current pages because you have to actually kind of assume that

01:34.630 --> 01:36.370
what is going to be the current page?

01:36.520 --> 01:40.000
Now current page is going to be one.

01:40.630 --> 01:42.400
So that is my assumption here.

01:42.490 --> 01:45.700
Again, I forgot a simple parenthesis.

01:45.700 --> 01:46.600
There we go.

01:46.600 --> 01:48.160
And I need to move this in.

01:48.160 --> 01:48.940
There we go.

01:48.940 --> 01:51.640
So I assumed that my current page is one.

01:51.640 --> 01:57.520
But there is a chance that inside this big query you might have passed me on a page number that is page

01:57.520 --> 01:58.120
equals to two.

01:58.120 --> 02:01.480
So I have to update this current page based on that if something is coming in.

02:01.480 --> 02:05.140
Otherwise, by default, all visitors current page is one.

02:05.140 --> 02:08.920
So let's just go ahead and say that if let's just access this one.

02:08.920 --> 02:16.120
So this dot big Q So inside this big query, if there is a dot page variable available, then only I'm

02:16.120 --> 02:21.160
going to go ahead and say, hey, let's just go ahead and update this current page to equal to whatever

02:21.160 --> 02:21.790
the value is.

02:21.790 --> 02:28.870
So this dot big query, dot page, so it will obviously key value properties like this.

02:28.870 --> 02:34.390
So I'm accessing the key of page, it will give me a value and that will be added to the current page.

02:34.630 --> 02:36.610
That is nice if that value exists.

02:37.930 --> 02:45.760
Now the thing is really simple that I have to simply go ahead and say that, hey, this dot base and

02:45.760 --> 02:48.910
inside this dot base, we're going to go ahead and add this one.

02:48.910 --> 02:54.010
So again, previously we were saying this dot find, but this time we have to use two things.

02:54.010 --> 02:57.730
This dot limit, it will get some value as well, not limité.

02:57.730 --> 02:59.200
That looks like French.

02:59.260 --> 03:02.530
Again, we're going to go ahead and add a skip value here as well.

03:02.860 --> 03:03.280
Okay.

03:03.310 --> 03:05.860
So these two values we need to work on with that.

03:05.950 --> 03:08.320
So how much is the limit?

03:08.320 --> 03:09.460
Limit is pretty simple.

03:09.460 --> 03:13.270
I can just go ahead and grab this result per page, so I'm going to go ahead and add this one.

03:13.270 --> 03:14.170
So there we go.

03:14.500 --> 03:20.260
Now, the important part is how can I find that how many values I have to skip?

03:20.260 --> 03:26.140
Because on the page one, I have to skip zero values on the page too.

03:26.140 --> 03:29.230
Let's just say we are going for five page per result.

03:29.230 --> 03:31.300
I have to skip five values.

03:31.300 --> 03:34.750
Then on the third page I have to skip the ten values.

03:34.750 --> 03:38.830
So this is a little bit of a complex work, not really that much complex.

03:38.920 --> 03:41.200
There is a well-known formula for that.

03:41.200 --> 03:42.550
So let's go ahead and work on with that.

03:42.550 --> 03:45.820
So we're going to go ahead and say, hey, how many values I have to skip?

03:46.120 --> 03:52.720
Skip Well, that is actually calculated and that is why we actually need this result per page.

03:52.720 --> 03:58.060
So the formula is really simple result per page is going to go ahead and multiply by whatever the current

03:58.060 --> 04:04.120
page value is, and we have to subtract one from it because on the first page we actually shows all

04:04.120 --> 04:04.750
the values.

04:04.750 --> 04:07.300
So again, you can go ahead and try to test these values.

04:07.300 --> 04:10.180
So in the result per page, let's just say we have five values.

04:10.180 --> 04:14.530
So five, let's just go ahead and do some of the mathematics because I know some of you will become

04:14.620 --> 04:15.310
confused.

04:15.310 --> 04:20.230
So result per page is five and we are going to go ahead and multiply it by.

04:20.800 --> 04:23.110
Let's just say we are on to the first page.

04:23.110 --> 04:25.840
So one minus one is going to be zero.

04:25.840 --> 04:28.090
So you'll be showing zero values on that.

04:28.090 --> 04:30.610
But the current page is actually going.

04:30.610 --> 04:32.650
So we are going to basically skip zero values.

04:32.650 --> 04:34.420
So that's what this basically means.

04:34.420 --> 04:35.290
So in this case.

04:35.290 --> 04:41.050
But what about if we are on to the second page to two minus one, that means we are on the first page.

04:41.050 --> 04:42.910
So how many values we go to skip?

04:42.910 --> 04:44.020
One five.

04:44.050 --> 04:46.480
You get the idea so you can do more mathematics of that.

04:46.480 --> 04:48.100
I wouldn't be doing much more than this.

04:48.100 --> 04:52.930
This is a very well known formula for all the pagination and you can go ahead and add a skip well onto

04:52.930 --> 04:53.440
that.

04:53.740 --> 04:59.470
It is so much well known that a lot of people actually kind of buy hard this one and we need to update

04:59.470 --> 05:00.460
the query as well.

05:00.460 --> 05:01.720
So whatever the.

05:01.820 --> 05:02.940
Where he actually came in.

05:02.960 --> 05:08.780
Now, this is the fresh, fresh base that we have got up here.

05:08.960 --> 05:10.820
So let's go ahead and do this one again.

05:10.820 --> 05:15.260
Product find is going to be as a test, whatever the value you have injected in the search and everything.

05:15.260 --> 05:19.730
And on top of that, further down the road, we are actually adding limit and skip on to this one.

05:19.730 --> 05:21.170
So let's go ahead and add this one.

05:21.170 --> 05:25.250
So this one is going to be this dot base is going to be like this one.

05:25.250 --> 05:30.440
So further down the road, a dot find and then we are adding dot limit and dot skip whatever we are

05:30.440 --> 05:31.010
having.

05:31.430 --> 05:36.530
Okay, further down the road, let's go ahead and simply say return this and that's it.

05:36.530 --> 05:38.210
We are returning the entire reference.

05:38.360 --> 05:39.560
So again, really simple.

05:39.560 --> 05:41.840
And again, you will be using this line quite a lot.

05:41.840 --> 05:47.720
So in case you want to go ahead and add this one on to your notes or somewhere, go ahead and do that.

05:47.720 --> 05:49.040
That's a simple page for you.

05:49.040 --> 05:50.870
Let's go ahead and catch up in the next video.
