Theme

Examples › Implementing infinite scrolling

See it in action:
DustinSawaynDustin.Sawayn@yahoo.com
EarnestHellerEarnest6@yahoo.com
SheilaKesslerSheila.Kessler@hotmail.com
BrayanMacejkovicBrayan3@hotmail.com
AssuntaAnkundingAssunta79@gmail.com
JavonteSchummJavonte14@gmail.com
JenniferVonJennifer_Von87@hotmail.com
MozellBeckerMozell.Becker@yahoo.com
HoraceBayerHorace.Bayer24@yahoo.com
ChaunceyHoegerChauncey.Hoeger7@gmail.com
RemingtonHansenRemington.Hansen9@yahoo.com
SammyMayerSammy.Mayer19@yahoo.com
MarilouMorarMarilou.Morar@gmail.com
ArmandoZiemeArmando_Zieme@gmail.com
DakotaLittleDakota.Little@gmail.com
TysonHowellTyson_Howell60@hotmail.com
BartholomeGibsonBartholome.Gibson@hotmail.com
LetaCorwinLeta_Corwin@yahoo.com
GeovanyKoelpinGeovany_Koelpin97@hotmail.com
CelineFeestCeline_Feest@hotmail.com
AlannaBashirianAlanna56@yahoo.com
EldredGrantEldred.Grant@yahoo.com
FreddyGottliebFreddy_Gottlieb@gmail.com
ImmanuelWolffImmanuel.Wolff18@gmail.com
DevanteJakubowskiDevante98@yahoo.com
IleneGreenIlene.Green36@gmail.com
EstevanRyanEstevan_Ryan35@gmail.com
JeffryRobertsJeffry.Roberts61@yahoo.com
EthaKerlukeEtha52@gmail.com
HansBaumbachHans79@yahoo.com
FelipeKuhlmanFelipe_Kuhlman@yahoo.com
AlfredJacobsAlfred.Jacobs2@gmail.com
VivaSchmittViva_Schmitt58@yahoo.com
EmilianoKesslerEmiliano25@gmail.com
ReymundoParisianReymundo.Parisian81@yahoo.com
CarleeWehnerCarlee_Wehner@gmail.com
VictorKiehnVictor.Kiehn89@yahoo.com
TrentonCroninTrenton12@yahoo.com
JackelineMuellerJackeline.Mueller@yahoo.com
MasonReynoldsMason_Reynolds@hotmail.com
MylesSchambergerMyles.Schamberger@yahoo.com
JohnMurazikJohn_Murazik@gmail.com
GeraldTerryGerald56@yahoo.com
HazelTrantowHazel98@yahoo.com
LitzyHarrisLitzy_Harris38@gmail.com
LeonieStrosinLeonie_Strosin@hotmail.com
IlaRunolfsdottirIla45@gmail.com
DestinyJacobsonDestiny40@yahoo.com
ChristopTillmanChristop.Tillman@yahoo.com
CurtisParkerCurtis_Parker@gmail.com
OttoBoehmOtto.Boehm37@gmail.com
GeoffreyPacochaGeoffrey69@yahoo.com
ReinholdRosenbaumReinhold.Rosenbaum28@hotmail.com
AdanO'ConnerAdan_OConner51@gmail.com
KelleyKeeblerKelley.Keebler18@gmail.com
GenovevaNikolausGenoveva.Nikolaus@hotmail.com
AnaBraunAna94@yahoo.com
MarkPfannerstillMark_Pfannerstill74@hotmail.com
EsperanzaThompsonEsperanza36@yahoo.com
MaribelKuvalisMaribel_Kuvalis@yahoo.com
DorothyAndersonDorothy.Anderson@hotmail.com
JayneStiedemannJayne_Stiedemann75@gmail.com
ThaliaCronaThalia_Crona@yahoo.com
MaudeVonRuedenMaude.VonRueden@hotmail.com
EllieFraneyEllie.Franey@yahoo.com
KarleyHauckKarley_Hauck@yahoo.com
AmiyaLoweAmiya.Lowe83@hotmail.com
NicolaAdamsNicola48@yahoo.com
DarrinMooreDarrin.Moore@gmail.com
BradenHeathcoteBraden84@yahoo.com
GlennieBaileyGlennie_Bailey@gmail.com
AgustinaRueckerAgustina24@yahoo.com
SimThielSim_Thiel@gmail.com
ValentinFraneyValentin33@gmail.com
MableKautzerMable.Kautzer@yahoo.com
TorranceHalvorsonTorrance.Halvorson@gmail.com
EricaBoganErica.Bogan31@yahoo.com
AddisonSauerAddison12@gmail.com
CurtisRohanCurtis_Rohan@gmail.com
CaterinaHodkiewiczCaterina.Hodkiewicz14@yahoo.com
JarrettGloverJarrett.Glover@yahoo.com
JamarLemkeJamar1@hotmail.com
WinonaO'KeefeWinona86@yahoo.com
CandelarioKrisCandelario75@hotmail.com
MariaCasperMaria41@gmail.com
ShayleeLarkinShaylee.Larkin@hotmail.com
GenevieveCartwrightGenevieve.Cartwright@gmail.com
CurtisMcLaughlinCurtis.McLaughlin56@yahoo.com
UlisesFayUlises52@yahoo.com
IvahWeissnatIvah.Weissnat37@hotmail.com
DarrinCartwrightDarrin86@yahoo.com
WileyMcClureWiley11@hotmail.com
LouCummingsLou_Cummings62@gmail.com
JohnathonLeuschkeJohnathon29@hotmail.com
CarletonWittingCarleton91@yahoo.com
BrycenBergnaumBrycen.Bergnaum52@hotmail.com
LyricLindgrenLyric_Lindgren@gmail.com
CorrineKassulkeCorrine89@gmail.com
JohannaDietrichJohanna8@hotmail.com
GeorgiannaBruenGeorgianna.Bruen@gmail.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:
import { Button, Group, Text } from '@mantine/core';
import { DataTable } from 'mantine-datatable';
import { useEffect, useRef, useState } from 'react';
import employees from '~/data/employees.json';
export default 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
withBorder
borderRadius="sm"
height={300}
columns={[{ accessor: 'firstName' }, { accessor: 'lastName' }, { accessor: 'email' }]}
records={records}
fetching={loading}
onScrollToBottom={loadMoreRecords}
scrollViewportRef={scrollViewportRef}
/>
<Group mt="sm" mx="xs" position="apart">
<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>
</>
);
}

Mantine DataTable is trusted by

MIT LicenseSponsor the author
Built by Ionut-Cristian Florescu and these awesome people.
Please sponsor the project if you find it useful.
GitHub StarsNPM Downloads