<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lightning Datatable &#8211; Jitendra Zaa</title>
	<atom:link href="https://www.jitendrazaa.com/blog/tag/lightning-datatable/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.jitendrazaa.com/blog</link>
	<description>AI, Salesforce, ServiceNow &#38; Enterprise Tech Guides</description>
	<lastBuildDate>Wed, 26 Aug 2020 13:49:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">87744916</site><atom:link rel="search" type="application/opensearchdescription+xml" title="Search Jitendra Zaa" href="https://www.jitendrazaa.com/blog/wp-json/opensearch/1.1/document" />	<item>
		<title>Implement Infinite Scrolling for lightning-datatable</title>
		<link>https://www.jitendrazaa.com/blog/salesforce/implement-infinite-scrolling-for-lightning-data-table/</link>
					<comments>https://www.jitendrazaa.com/blog/salesforce/implement-infinite-scrolling-for-lightning-data-table/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Wed, 10 Jun 2020 04:06:35 +0000</pubDate>
				<category><![CDATA[Lightning Web Components]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[datatable]]></category>
		<category><![CDATA[Imperative Apex]]></category>
		<category><![CDATA[Lightning Datatable]]></category>
		<category><![CDATA[Lightning Web Component]]></category>
		<category><![CDATA[LWC]]></category>
		<category><![CDATA[Wire]]></category>
		<guid isPermaLink="false">https://www.jitendrazaa.com/blog/?p=7101</guid>

					<description><![CDATA[When to use wire vs Imperative approach to call Apex in Lightning Web Component]]></description>
										<content:encoded><![CDATA[
<p class="justify">If you are thinking this post is about <strong>implementing infinite scrolling behavior</strong> for <strong><a href="https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/example">lightning-datatable</a></strong> component, then you only got half part right. Main purpose of this blog post is to compare side by side<strong> @wire vs Imperative</strong> way of calling Apex and decide which one to use when?</p>



<p>If you are looking for <a href="https://www.jitendrazaa.com/blog/salesforce/getting-started-with-lightning-web-component/">basics of LW</a>C or <a href="https://www.jitendrazaa.com/blog/salesforce/point-and-click/use-lightning-web-components-in-flow/">how to use LWC in flow</a>, <a href="https://www.jitendrazaa.com/blog/salesforce/data-exchange-between-aura-lightning-web-components-lwc-and-visualforce/">Lightning Message Service</a>, <a href="https://www.jitendrazaa.com/blog/salesforce/gravatar-reusable-lightning-web-component/">how to call Apex</a> then <a href="https://www.jitendrazaa.com/blog/tag/lightning-web-component/">follow this link</a>.</p>



<p>In this post, you would learn</p>



<ul class="wp-block-list"><li>How to call Apex in LWC using <strong>@wire</strong></li><li>How to call Apex in LWC by <strong>Imperative</strong> approach</li><li>How to call Apex on component load event equivalent to init in Aura</li><li>Why would you choose to call Apex either by <strong>@wire</strong> or <strong>Imperative</strong> Apex approach</li><li>How to bind <strong>wrapper class</strong> in <strong><a href="https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/example">Lightning-datatable</a></strong> component</li><li>How to enable infinite scrolling in <strong><a href="https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/example">Lightning-datatable</a></strong> by making server call</li></ul>



<span id="more-7101"></span>



<p>Lets start with building demo <strong> lightning-datatable</strong> component with infinite scroll effect ,  below code is self explanatory so I would skip code explanation part. <a href="https://jit29-developer-edition.na85.force.com/blogdemo/s/lwcdemo">Click here for live demo of this component and test end result yourself.</a></p>



<script src="https://gist.github.com/JitendraZaa/e45244d3f6095b3cd1d46616c0178c2b.js"></script>



<p class="justify">Initially , it seems everything working as expected, however after some scroll , try to search any employee name. You would observe that Salesforce never made 2nd Apex call as <strong>cacheable=true</strong> was mentioned in Apex. Salesforce is trying to save resources. You cannot use wire method if <strong>cacheable is not true</strong>. This is great caching feature, unfortunately it didn&#8217;t sufficed our need. </p>



<p class="justify">Let&#8217;s do one more attempt, this time we would use <strong>Imperative approach</strong> and use <strong>connectedCallback</strong> method to make Apex call on component load. @wire decorator did this automatically on component load, this time we have to make explicit call. Another change , we have done is, we marked method as <strong>cacheable=false</strong>. <a href="https://jit29-developer-edition.na85.force.com/blogdemo/s/lwcdemo">Click here for live demo of this component and test end result yourself.</a></p>



<script src="https://gist.github.com/JitendraZaa/dab45e5c47829b0d96d9f78aa7583574.js"></script>



<p>Use below code to wrap both approach in single component</p>



<script src="https://gist.github.com/JitendraZaa/b3ccd976d72e417730396a8bc6fb5e69.js"></script>



<h3 class="wp-block-heading">Problem &#8211; It is making continuous server calls even when no one is scrolling</h3>



<p class="justify"><strong>Cause 1</strong> : Parent component needs to restrict height. If parent Div does not have height in pixel then it will keep calling Apex method. <a href="https://salesforce.stackexchange.com/questions/279776/lwc-lightning-datatable-infinite-scrolling-not-working">Read more about issue here</a></p>



<p class="justify"><strong>Cause 2 </strong>: Let&#8217;s say height is 300px but we have less component that does not fit 300px then this component would still make server call continuously. In that case height needs to be automatically adjusted or disable infinite scrolling if total record in component is not enough to fill height.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/salesforce/implement-infinite-scrolling-for-lightning-data-table/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7101</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.jitendrazaa.com @ 2026-04-17 07:42:32 by W3 Total Cache
-->