Examples › Infinite scrolling

Scroll the table to the bottom to see it in action:

First name
Last name
Email
JeraldHowellJerald.Howell32@yahoo.com
KathleenRueckerKathleen_Ruecker@hotmail.com
EricaVolkmanErica.Volkman37@gmail.com
CliffordOberbrunnerClifford.Oberbrunner@hotmail.com
AlisonKlingAlison16@gmail.com
SueZiemeSue.Zieme29@hotmail.com
FeliciaGleasonFelicia30@yahoo.com
AlfredoZemlakAlfredo22@yahoo.com
EmilyBartolettiEmily.Bartoletti@gmail.com
DeloresReynoldsDelores.Reynolds@yahoo.com
LouisSchambergerLouis6@yahoo.com
BeverlyHellerBeverly_Heller@gmail.com
EugeneFeestEugene88@hotmail.com
MartinBahringerMartin_Bahringer10@gmail.com
EllisMillerEllis36@hotmail.com
GloriaColeGloria41@gmail.com
LindaWittingLinda_Witting@yahoo.com
GreggKutchGregg_Kutch8@yahoo.com
MamieRaynorMamie58@hotmail.com
ErickBruenErick_Bruen13@yahoo.com
FaithLangworthFaith_Langworth14@gmail.com
AliciaLeannonAlicia62@yahoo.com
BoydMohrBoyd.Mohr@hotmail.com
LindseyHeidenreichLindsey31@yahoo.com
ElsaMarvinElsa.Marvin2@gmail.com
DebbieHagenesDebbie.Hagenes@hotmail.com
LionelMcCulloughLionel_McCullough@gmail.com
KimLebsackKim.Lebsack66@yahoo.com
RolandoWeissnatRolando83@hotmail.com
JacquelineLeschJacqueline35@hotmail.com
FelixStokesFelix77@hotmail.com
ReneeTillmanRenee.Tillman@yahoo.com
RichardWatsicaRichard_Watsica@yahoo.com
NathanWolfNathan.Wolf@gmail.com
JonathanKeebler-CronaJonathan.Keebler-Crona90@gmail.com
KathleenSpinkaKathleen_Spinka58@hotmail.com
BerniceSchinnerBernice45@hotmail.com
AdamPagacAdam58@hotmail.com
EarlRyanEarl.Ryan@gmail.com
GregBaileyGreg.Bailey@hotmail.com
AnnePowlowskiAnne_Powlowski69@gmail.com
AbrahamDooleyAbraham_Dooley@gmail.com
MyronLemkeMyron_Lemke@gmail.com
DiannaGislason-LeschDianna88@hotmail.com
ReginaldHagenesReginald_Hagenes51@gmail.com
SheliaTurcotteShelia68@yahoo.com
CarltonJenkinsCarlton_Jenkins62@gmail.com
LanceWiegandLance_Wiegand@gmail.com
RubyGrahamRuby20@hotmail.com
HattieCollierHattie60@hotmail.com
ViolaRathViola_Rath6@gmail.com
RolandHuelRoland_Huel@yahoo.com
LeticiaWiegandLeticia65@hotmail.com
JacquelineKulasJacqueline.Kulas@hotmail.com
CristinaJaskolskiCristina.Jaskolski@hotmail.com
FelipeDaughertyFelipe_Daugherty@hotmail.com
TimothyHeaneyTimothy.Heaney@gmail.com
AlonzoKutchAlonzo12@yahoo.com
KeithKlingKeith25@yahoo.com
JaniceGoyetteJanice93@gmail.com
HelenKunze-MacGyverHelen_Kunze-MacGyver@gmail.com
BarryJastBarry.Jast@yahoo.com
RamiroCummingsRamiro.Cummings30@hotmail.com
AntonioLittle-BahringerAntonio.Little-Bahringer@gmail.com
SamuelZemlakSamuel_Zemlak@gmail.com
DorisEmardDoris_Emard8@gmail.com
OliviaAbernathyOlivia_Abernathy@yahoo.com
JustinKohlerJustin_Kohler42@hotmail.com
ScottOberbrunnerScott.Oberbrunner57@hotmail.com
YolandaSpinkaYolanda.Spinka76@hotmail.com
BradUllrich-OrnBrad30@yahoo.com
GloriaFisherGloria.Fisher22@gmail.com
SergioCristSergio_Crist93@gmail.com
TheresaSporerTheresa.Sporer85@hotmail.com
TheodoreWiegandTheodore58@yahoo.com
RudyRoweRudy_Rowe25@gmail.com
KurtRaynorKurt.Raynor@hotmail.com
RuthMedhurstRuth.Medhurst97@yahoo.com
TimAbernathyTim0@yahoo.com
RebeccaRunolfsdottirRebecca.Runolfsdottir41@gmail.com
AngelAufderharAngel.Aufderhar19@yahoo.com
JavierBergstromJavier12@yahoo.com
LeighKlockoLeigh.Klocko77@hotmail.com
TaylorRiceTaylor30@yahoo.com
CindyGoldnerCindy_Goldner47@yahoo.com
ShannonCristShannon88@hotmail.com
SarahMaggioSarah54@hotmail.com
CarltonLangosh-GloverCarlton.Langosh-Glover@gmail.com
FeliciaRoobFelicia_Roob65@yahoo.com
SimonKuhicSimon30@yahoo.com
SharonDanielSharon.Daniel2@hotmail.com
ErinBayerErin4@hotmail.com
ErikaPowlowski-CorwinErika33@gmail.com
VickyPollichVicky_Pollich18@hotmail.com
FeliciaZiemannFelicia.Ziemann56@gmail.com
ColleenCrooksColleen84@hotmail.com
JimmyFisherJimmy7@yahoo.com
LulaReichertLula.Reichert48@gmail.com
BethanySchinnerBethany.Schinner@yahoo.com
AllenHackettAllen44@hotmail.com
No records

Showing 100 records of 500, scroll to bottom to load more

The DataTable triggers onScrollToTop, onScrollToBottom, onScrollToRight and onScrollToLeft callbacks when user scrolls to the top, bottom, left or right edge of the table. You can use the onScrollToBottom event to implement infinite scrolling, like so:

'use client';

import { Button, Group, Paper, Text } from '@mantine/core';
import { DataTable } from 'mantine-datatable';
import { useEffect, useRef, useState } from 'react';
import { employees } from '~/data';

export function InfiniteScrollingExample() {
  const batchSize = 100;
  const [loading, setLoading] = useState(false);
  const [records, setRecords] = useState(employees.slice(0, batchSize));
  const scrollViewportRef = useRef<HTMLDivElement>(null);

  let timeout: ReturnType<typeof setTimeout> | undefined;

  const loadMoreRecords = () => {
    if (records.length < employees.length) {
      setLoading(true);
      timeout = setTimeout(() => {
        setRecords(employees.slice(0, records.length + batchSize));
        setLoading(false);
      }, 1000);
    }
  };

  const reset = () => {
    setRecords(employees.slice(0, batchSize));
    // Make sure to scroll to top after resetting records
    scrollViewportRef.current?.scrollTo(0, 0);
  };

  // Clear timeout on unmount
  useEffect(() => {
    return () => {
      if (timeout) clearTimeout(timeout);
    };
  }, [timeout]);

  return (
    <>
      <DataTable
        withTableBorder
        borderRadius="sm"
        height={300}
        columns={[{ accessor: 'firstName' }, { accessor: 'lastName' }, { accessor: 'email' }]}
        records={records}
        fetching={loading}
        onScrollToBottom={loadMoreRecords}
        scrollViewportRef={scrollViewportRef}
      />
      <Paper p="md" mt="sm" withBorder>
        <Group justify="space-between">
          <Text size="sm">
            Showing {records.length} records of {employees.length}
            {records.length < employees.length && ', scroll to bottom to load more'}
          </Text>
          <Button variant="light" onClick={reset}>
            Reset records
          </Button>
        </Group>
      </Paper>
    </>
  );
}

Head over to the next example to discover more features.