Lazyload Data Table

How To

  1. Step 1: Include LambdaEx Framework in Logi Info Application. Include LambdaEx Framework in Logi Info Application.
  2. Step 2: Important: Add default request params page and RowsPerPage.
  3. Step 3: Include northwind.xml source files in Logi Info ApplicationInclude northwind.xml source files in Logi Info Application
<DefaultRequestParams page="1" RowsPerPage="2" />
<DefaultRequestParams page="1" RowsPerPage="2" />

The Basics

Scroll/Load Listener
$(window).on('load scroll', function() {
   //Scroll position is 300px from bottom.
   if($(window).scrollTop() + $(window).height() > $(document).height() - 300) {
      ... 	  
   }
});
Ajax Call
$.ajax({
   url: './rdPageAsync.aspx?rdReport=[at]Request.rdReport[tilde]&page='+nextPage, 
   async: true,
   success: function(responseData) {
      //Append response to current table
   }
});
SQL
DECLARE [at]page INT=[at]Request.page[tilde];
DECLARE [at]RowsPerPage INT=[at]Request.RowsPerPage[tilde];
SELECT * 
FROM (SELECT * 
             , ROW_NUMBER() OVER(ORDER BY ProductID) AS RowNum 
      FROM Products) tbl
WHERE RowNum > ([at]RowsPerPage * [at]page - [at]RowsPerPage) 
  AND RowNum <= ([at]RowsPerPage * [at]page)
Lazy Example
ProductIDProduct NameQuantity Per UnitPriceUnits In StockUnits On OrderReorder Level
1Chai10 boxes x 20 bags$18.0039010
2Chang24 - 12 oz bottles$19.00174025

Full Example

Add .blur class to stylesheet for last row animation.
.blur {
	transition: all 0.500s ease-out;
	-webkit-filter: blur(5px) grayscale(0.5);
}
<DataTable Class="table table-striped" ID="dtLazyLoad">
  <DataLayer JsonFile="Data.Products.json" Type="JsonFile" XPath="rdData/dtLazyLoad/Products/Product">
    <ConditionFilter Condition="[at]Data.-ProductID[tilde] &gt;= (([at]Request.page[tilde]-1)*[at]Request.RowsPerPage[tilde])+1 AND [at]Data.-ProductID[tilde] &lt;= ([at]Request.page[tilde]*[at]Request.RowsPerPage[tilde])" />
  </DataLayer>
  <AutoColumns />
</DataTable>
<Label Class="text-danger" ID="lblMessage" />
/*START INCLUDE SCRIPT ELEMENT...*/
var nextPage = [at]Request.page[tilde];
var isRunning = false;
$(window).on('load scroll', function() {
   //Set timeout interval to keep scroll listener from firing multiple times.
   if(!isRunning)
      scrollHandler();
});
scrollHandler = function () {
   isRunning = true;  
   if($(window).scrollTop() + $(window).height() > $(document).height() - 2200) {
      nextPage++;
      var DataTableName = $('[id^=rdDataTableDiv]>table').attr('id');
      var AjaxUrl = './rdPageAsync.aspx?rdReport=[at]Request.rdReport[tilde]&page='+nextPage;
      $.ajax({
         url: AjaxUrl, 
         async: true,
         success: function(responseData) {
            var rowsData = $(responseData).find('#'+DataTableName+'>tbody>tr');
            var rowNum = ((nextPage-1)*[at]Request.RowsPerPage[tilde])+1;
            rowsData.each(function() {
               rowNum++;
               $('#'+DataTableName+' tr.blur').removeClass('blur');
               $(this).attr('row', rowNum).addClass('blur');
               $('#'+DataTableName+'>tbody').append($(this));
            });
            
            if(rowsData.length == 0){                  
               //Finished
               $('#'+DataTableName+' tr.blur').removeClass('blur');
               $('#lblMessage').html('End of data...').delay(1500).fadeOut();
               $(window).unbind('scroll');
            }
            else {
               scrollHandler();
            }
         }
      });
   }
   else {
      isRunning = false;        
      $('.blur').removeClass('blur');
   }
};
/*...END INCLUDE SCRIPT*/
<Division ID="dvExample" HtmlDiv="True"> <DataTable Class="table table-striped" ID="dtLazyLoad"> <DataLayer JsonFile="Data.Products.json" Type="JsonFile" XPath="rdData/dtLazyLoad/Products/Product"> <ConditionFilter Condition=" &gt;= ((1-1)*2)+1 AND &lt;= (1*2)" IncludeCondition="'1' != ''" /> </DataLayer> <AutoColumns /> </DataTable> <Label Class="text-danger" ID="lblMessage" /> <IncludeScript IncludedScript="var nextPage = parseInt('1' || 1);&#xD;&#xA;var rowsPerPage = parseInt('2' || 1);&#xD;&#xA;var isRunning = false;&#xD;&#xA;$(window).on('load scroll', function() {&#xD;&#xA; //Set timeout interval to keep scroll listener from firing multiple times.&#xD;&#xA; if(!isRunning)&#xD;&#xA; scrollHandler();&#xD;&#xA;});&#xD;&#xA;scrollHandler = function () {&#xD;&#xA; isRunning = true; &#xD;&#xA; if($(window).scrollTop() + $(window).height() &gt; $(document).height() - 500) {&#xD;&#xA; nextPage++;&#xD;&#xA; var DataTableName = $('[id^=rdDataTableDiv]&gt;table').attr('id');&#xD;&#xA; var AjaxUrl = './rdPageAsync.aspx?rdReport=Extend.LazyDataTable&amp;page='+nextPage;&#xD;&#xA; $.ajax({&#xD;&#xA; url: AjaxUrl, &#xD;&#xA; async: true,&#xD;&#xA; success: function(responseData) {&#xD;&#xA; var rowsData = $(responseData).find('#'+DataTableName+'&gt;tbody&gt;tr');&#xD;&#xA; var rowNum = ((nextPage-1)*rowsPerPage)+1;&#xD;&#xA; rowsData.each(function() {&#xD;&#xA; rowNum++;&#xD;&#xA; $('#'+DataTableName+' tr.blur').removeClass('blur');&#xD;&#xA; $(this).attr('row', rowNum).addClass('blur');&#xD;&#xA; $('#'+DataTableName+'&gt;tbody').append($(this));&#xD;&#xA; });&#xD;&#xA; &#xD;&#xA; if(rowsData.length == 0){&#xD;&#xA; $(window).unbind('scroll');&#xD;&#xA; $('#lblMessage').html('End of data...');&#xD;&#xA; setTimeout(function() {&#xD;&#xA; $('#lblMessage').fadeOut();&#xD;&#xA; }, 1500);&#xD;&#xA; }&#xD;&#xA; else {&#xD;&#xA; scrollHandler();&#xD;&#xA; }&#xD;&#xA; }&#xD;&#xA; });&#xD;&#xA; }&#xD;&#xA; else {&#xD;&#xA; isRunning = false; &#xD;&#xA; $('.blur').removeClass('blur');&#xD;&#xA; }&#xD;&#xA;};&#xD;&#xA;" /> </Division>