Theme

Examples › Searching and filtering

Dustin SawaynIndustrialRunolfsdottir - CummerataMay 20 198043
Earnest HellerHealthJohnston LLCNov 26 199132
Sheila KesslerAutomotiveSipes IncApr 12 198241
Brayan MacejkovicBabyJohnston LLCJun 30 194677
Assunta AnkundingBooksCrist and SonsMay 26 197845
Javonte SchummClothingRunolfsdottir - CummerataMar 04 195667
Jennifer VonShoesWelch - TremblayFeb 22 198538
Mozell BeckerGroceryJakubowski - RolfsonSep 20 197449
Horace BayerHomeJakubowski - RolfsonJul 04 199627
Chauncey HoegerClothingJohnston LLCApr 08 198241
Remington HansenOutdoorsNicolas GroupApr 17 196756
Sammy MayerOutdoorsCrist and SonsJul 12 197251
Marilou MorarShoesRunolfsdottir - CummerataJul 30 197449
Armando ZiemeAutomotiveJakubowski - RolfsonOct 08 197647
Dakota LittleMoviesCrist and SonsSep 01 197746
Tyson HowellToolsKub and SonsJan 02 199232
Bartholome GibsonOutdoorsCrist and SonsDec 26 200518
Leta CorwinGardenNicolas GroupDec 02 198340
Geovany KoelpinMoviesRunolfsdottir - CummerataSep 27 197944
Celine FeestGamesSipes IncFeb 18 196855
Alanna BashirianGardenSipes IncJun 15 200518
Eldred GrantOutdoorsJakubowski - RolfsonMar 11 197152
Freddy GottliebClothingCrist and SonsJan 19 195172
Immanuel WolffOutdoorsSipes IncMar 08 195964
Devante JakubowskiGardenSipes IncJun 30 196162
Ilene GreenToysRunolfsdottir - CummerataApr 20 196162
Estevan RyanShoesJohnston LLCMay 21 195172
Jeffry RobertsShoesJohnston LLCNov 11 197251
Etha KerlukeBabyRunolfsdottir - CummerataJul 25 196756
Hans BaumbachKidsWelch - TremblayApr 29 197053
Felipe KuhlmanToolsNicolas GroupApr 01 197350
Alfred JacobsOutdoorsRunolfsdottir - CummerataSep 10 196459
Viva SchmittGardenSipes IncSep 20 197251
Emiliano KesslerToysNicolas GroupMay 30 200122
Reymundo ParisianHomeJohnston LLCMay 11 194875
Carlee WehnerShoesRunolfsdottir - CummerataOct 06 197251
Victor KiehnIndustrialJohnston LLCJul 02 197746
Trenton CroninMusicJakubowski - RolfsonSep 22 199627
Jackeline MuellerHomeJohnston LLCApr 17 198439
Mason ReynoldsGardenSipes IncSep 10 195073
Myles SchambergerSportsJohnston LLCNov 04 198439
John MurazikMusicJohnston LLCMay 14 198835
Gerald TerryIndustrialSipes IncMar 09 199429
Hazel TrantowMusicJohnston LLCJun 23 195271
Litzy HarrisMusicWelch - TremblayAug 15 198538
Leonie StrosinAutomotiveSipes IncSep 19 194875
Ila RunolfsdottirAutomotiveSchmidt and SonsJul 23 200023
Destiny JacobsonSportsJohnston LLCApr 13 195865
Christop TillmanToolsWelch - TremblayMay 08 199033
Curtis ParkerAutomotiveRunolfsdottir - CummerataMar 11 194578
Otto BoehmShoesRunolfsdottir - CummerataJan 30 200122
Geoffrey PacochaBabyJohnston LLCFeb 25 194578
Reinhold RosenbaumJeweleryJohnston LLCFeb 08 198637
Adan O'ConnerElectronicsSchmidt and SonsDec 14 197548
Kelley KeeblerOutdoorsRunolfsdottir - CummerataAug 27 197152
Genoveva NikolausBeautyCrist and SonsDec 06 196360
Ana BraunBooksCrist and SonsJun 08 200023
Mark PfannerstillHealthMueller, Hodkiewicz and BeahanFeb 01 196756
Esperanza ThompsonKidsRunolfsdottir - CummerataJun 29 198538
Maribel KuvalisBabyMueller, Hodkiewicz and BeahanDec 01 196261
Dorothy AndersonOutdoorsJakubowski - RolfsonOct 12 199924
Jayne StiedemannGamesKub and SonsJun 10 196954
Thalia CronaComputersMueller, Hodkiewicz and BeahanNov 30 199033
Maude VonRuedenClothingJakubowski - RolfsonApr 19 196360
Ellie FraneyIndustrialRunolfsdottir - CummerataMar 02 199330
Karley HauckSportsJohnston LLCApr 11 194776
Amiya LoweBeautyMueller, Hodkiewicz and BeahanApr 23 194677
Nicola AdamsGroceryCrist and SonsApr 19 195172
Darrin MooreAutomotiveCrist and SonsDec 30 200320
Braden HeathcoteToysCrist and SonsMar 01 195172
Glennie BaileyOutdoorsCrist and SonsApr 20 198142
Agustina RueckerShoesKub and SonsMay 30 195766
Sim ThielBeautySipes IncJun 12 197251
Valentin FraneyBooksCrist and SonsApr 21 194578
Mable KautzerMusicJakubowski - RolfsonNov 25 198241
Torrance HalvorsonOutdoorsSipes IncJul 10 198142
Erica BoganElectronicsJohnston LLCMar 22 200023
Addison SauerGardenCrist and SonsApr 06 198835
Curtis RohanBabySipes IncJan 10 199529
Caterina HodkiewiczMoviesRunolfsdottir - CummerataAug 16 195271
Jarrett GloverHealthMueller, Hodkiewicz and BeahanMay 12 194974
Jamar LemkeHealthJakubowski - RolfsonJan 14 195272
Winona O'KeefeJewelerySchmidt and SonsMar 17 197548
Candelario KrisKidsSchmidt and SonsNov 30 195469
Maria CasperClothingSchmidt and SonsAug 23 197845
Shaylee LarkinBooksWelch - TremblayOct 13 197944
Genevieve CartwrightGardenNicolas GroupJul 14 195865
Curtis McLaughlinSportsCrist and SonsAug 03 194677
Ulises FayGardenSipes IncNov 13 195073
Ivah WeissnatHomeMueller, Hodkiewicz and BeahanOct 30 196063
Darrin CartwrightMoviesNicolas GroupNov 25 198934
Wiley McClureOutdoorsJakubowski - RolfsonJun 03 196063
Lou CummingsKidsSchmidt and SonsNov 11 199627
Johnathon LeuschkeGroceryJakubowski - RolfsonApr 05 194974
Carleton WittingGardenSipes IncFeb 06 195568
Brycen BergnaumGardenNicolas GroupSep 22 196063
Lyric LindgrenGroceryJakubowski - RolfsonApr 29 197944
Corrine KassulkeToolsJakubowski - RolfsonDec 15 199429
Johanna DietrichGroceryMueller, Hodkiewicz and BeahanAug 15 196954
Georgianna BruenGrocerySipes IncMay 05 195568
No records
Adjust the array of records you’re feeding to Mantine DataTable based on your own logic in order to perform searching and filtering.
In order to support column-based filtering you can use the filter and filtering column properties.
Here’s a possible (rather naive) implementation:
import { Box, Button, MultiSelect, Stack, TextInput } from '@mantine/core';
import { DatePicker, type DatesRangeValue } from '@mantine/dates';
import { useDebouncedValue } from '@mantine/hooks';
import { IconSearch } from '@tabler/icons-react';
import dayjs from 'dayjs';
import { DataTable } from 'mantine-datatable';
import { useEffect, useMemo, useState } from 'react';
import { employees } from '~/data';
const initialRecords = employees.slice(0, 100);
export default function SearchingAndFilteringExample() {
const [records, setRecords] = useState(initialRecords);
const departments = useMemo(() => {
const departments = new Set(employees.map((e) => e.department.name));
return [...departments];
}, []);
const [query, setQuery] = useState('');
const [selectedDepartments, setSelectedDepartments] = useState<string[]>([]);
const [birthdaySearchRange, setBirthdaySearchRange] = useState<DatesRangeValue>();
const [debouncedQuery] = useDebouncedValue(query, 200);
useEffect(() => {
setRecords(
initialRecords.filter(({ firstName, lastName, department, birthDate }) => {
if (
debouncedQuery !== '' &&
!`${firstName} ${lastName}`.toLowerCase().includes(debouncedQuery.trim().toLowerCase())
) {
return false;
}
if (
birthdaySearchRange &&
birthdaySearchRange[0] &&
birthdaySearchRange[1] &&
(dayjs(birthdaySearchRange[0]).isAfter(birthDate, 'day') ||
dayjs(birthdaySearchRange[1]).isBefore(birthDate, 'day'))
) {
return false;
}
if (selectedDepartments.length && !selectedDepartments.some((d) => d === department.name)) {
return false;
}
return true;
})
);
}, [debouncedQuery, birthdaySearchRange, selectedDepartments]);
return (
<Box sx={{ height: 300 }}>
<DataTable
withBorder
records={records}
columns={[
{
accessor: 'name',
render: ({ firstName, lastName }) => `${firstName} ${lastName}`,
filter: (
<TextInput
label="Employees"
description="Show employees whose names include the specified text"
placeholder="Search employees..."
icon={<IconSearch size={16} />}
value={query}
onChange={(e) => setQuery(e.currentTarget.value)}
/>
),
filtering: query !== '',
},
{
accessor: 'department.name',
filter: (
<MultiSelect
label="Departments "
description="Show all employees working at the selected departments"
data={departments}
value={selectedDepartments}
placeholder="Search departments…"
onChange={setSelectedDepartments}
icon={<IconSearch size={16} />}
clearable
searchable
/>
),
filtering: selectedDepartments.length > 0,
},
{ accessor: 'department.company.name' },
{
accessor: 'birthDate',
render: ({ birthDate }) => dayjs(birthDate).format('MMM DD YYYY'),
filter: ({ close }) => (
<Stack>
<DatePicker
maxDate={new Date()}
type="range"
value={birthdaySearchRange}
onChange={setBirthdaySearchRange}
/>
<Button
disabled={!birthdaySearchRange}
color="red"
onClick={() => {
setBirthdaySearchRange(undefined);
close();
}}
>
Reset
</Button>
</Stack>
),
filtering: Boolean(birthdaySearchRange),
},
{ accessor: 'age', render: ({ birthDate }) => dayjs().diff(birthDate, 'y') },
]}
/>
</Box>
);
}

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