Salesforce Lighting Web Component datatable rows selection across pagination
298 views
Nov 6, 2024
We can achieve rows selections across multiple pages when using pagination in lightning-datatable, by storing the selected rows in a variable. Blog Post: https://www.infallibletechie.com/2024/11/salesforce-lighting-web-component-datatable-rows-selection-across-pagination.html
View Video Transcript
0:07
hello everyone in this video we are
0:10
going to see how to hold records
0:15
selection when we use Salesforce
0:18
lightning web component lightning data
0:21
table let's see a demo here I'm going to
0:24
search accounts starting with the
0:28
test it is displaying uh five account
0:33
records I'm selecting couple of account
0:36
records if I click next it goes to the
0:39
next uh set of
0:41
Records I'm going to select one record
0:44
here and another record here so totally
0:46
I selected four records two from first
0:49
page two from second page and one from
0:53
another page so though I am navigating
0:56
from one page to another page I'm able
0:59
to hold the selected account
1:03
records I created this Apex class to
1:06
fetch the account
1:09
records I'm using the SQL like select ID
1:13
comma name comma industry from account
1:15
and then I'm making sure I'm using like
1:18
operator for searching of account and I
1:22
am also using and condition using last
1:26
account ID for example here
1:31
so here if once it gives me five account
1:34
records it will store this account
1:36
record ID as the last account ID for the
1:39
next it will search account records
1:42
greater than this particular testing to
1:44
account record and then it will get the
1:46
next set of fire
1:48
records in order to do that pagination I
1:51
am using this if I go uh and also I'm
1:55
storing the first account record ID
2:00
um so that uh it it will uh uh decrease
2:04
it and get
2:08
it so the Sorting will happen in
2:11
descending order and then it will get
2:12
the proper pre previous set of account
2:15
records uh the advantage of using this
2:18
approach is if you if we use offset uh
2:21
the maximum offset value can be 2,000 so
2:24
we can avoid hitting that 2,000 limit
2:28
and also uh in some pagination uh use
2:33
cases we have to query all the records
2:35
and then we have to iterate and show it
2:38
uh in this case we can fetch um only
2:40
when it is needed from the database
2:42
display it on the screen and then the
2:43
users will be able to uh select
2:46
it uh we we won't have that 50,000 SQL
2:51
limit also we can query as you as we
2:54
want since we are using pagination and
2:56
then we will be able to uh display it on
2:58
the screen for the users selection uh
3:01
this is the lightning web component I
3:03
have
3:07
created and I created the target as a
3:10
lightning underscore uncore tab so that
3:12
I can display it on the tab if you
3:15
wanted to uh achieve a similar
3:17
requirement you can make use of the uh
3:20
lightning web component code and the
3:21
Apex class which I have used for your
3:24
reference please check the video
3:26
description in the video description I
3:28
have shared my blog post from the blog
3:30
post you should be able to get the
3:32
sample lightning web component code and
3:33
the Apex code for your
3:39
reference I hope it was
3:44
helpful thank you for watching
#Internet Software