Hi,
I’m using Airtable-js to build a website using my Airtable as a source.
Because my table has 800 records, I’ve added a click event before fetching more pages of my table, but fetchNextPage is behaving strangely. Instead of fetching regular blocks (my page limit is 36), each request seems to be multiplied by two, thus first it works, then it returns a duplicate block, and eventually it bloats to the point of hanging.
Check the code below. You can see eachPage renders more cards whenever I hit the bottom of the page.
function updateTable () {
table.select({
maxRecords: 800,
pageSize: 36,
view: "Grid view",
filterByFormula: filterDefault,
sort: sortDefault}
).eachPage(function page(records, fetchNextPage) {
records.forEach(function(record) {
var rc = record.fields;
var $dataContainer = $('#data-container');
var $cardAlign = $('<div class="d-flex align-items-stretch col-xs-12 col-sm-6 col-md-4 col-lg-2" data-toggle="modal" data-target="#myModal" />');
if(rc.Centuries){var cent = 'c' + rc.Centuries.join("")} else {var cent = ""};
var $galleryCard = $('<div class="card mx-auto ' + cent + '" />');
$($galleryCard).attr('id', record.id);
var $picture = $('<picture />');
if (rc.Image) {
$('<img class="card-img-top" />').attr('src', rc.Imagem0].url).appendTo($picture);
}
var $label = $('<div class="card-body" />').text(rc.Nome);
$galleryCard.append($picture);
$galleryCard.append($label);
$cardAlign.append($galleryCard);
$dataContainer.append($cardAlign);
});
$(window).on('scroll', function(){
var scrollHeight = $(document).height();
var scrollPos = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPos) / scrollHeight == 0) {
fetchNextPage();
}
});
}, function done(err) {
if (err) { console.error(err); return; }
});
}