React Agenda Event Search
Get started with this exampleUsage
theme="ios" You can turn auto theming on and let it decide based on the platform.
Usage
themeVariant="light" You can turn auto dark mode on based on system settings.
Usage
locale={localeEn} Selecting the locale loads the localized settings and the translated UI text.
Event Search
Use the available real estate in the calendar header to add event search. With the templating capabilities of the header you can easily add a search box and use a separate agenda instance to show the search results. This example is relying on a single API endpoint for getting the data onto the primary view and also for getting the filtered data based on the search terms.
Events can be filtered in real time so using an agenda view for the search results is an easy choice. It provides all the necessary styling and advanced features that you might need to customize the experience.
Alternatively, search can be implemented in a sidebar next to the event calendar using a similar search box with an inline agenda instead of a dropdown.
Demo

Code
View code on GitHub
import {
CalendarNav,
CalendarNext,
CalendarPrev,
CalendarToday,
Eventcalendar,
formatDate,
getJson,
Input,
Popup,
setOptions ,
} from '@mobiscroll/react';
import { useCallback, useMemo, useRef, useState } from 'react';
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
});
function App() {
const [calEvents, setCalEvents] = useState([]);
const [isPopupOpen, setPopupOpen] = useState(false);
const [listEvents, setListEvents] = useState([]);
const [searchInput, setSearchInput] = useState(null);
const [selectedEvent, setSelectedEvent] = useState([]);
const calInst = useRef();
const timer = useRef(null);
const calView = useMemo(() => ({ agenda: { type: 'month' } }), []);
const listView = useMemo(() => ({ agenda: { type: 'year', size: 5 } }), []);
const handleInputChange = useCallback((ev) => {
const searchText = ev.target.value;
clearTimeout(timer.current);
timer.current = setTimeout(() => {
if (searchText.length > 0) {
getJson(
'https://trial.mobiscroll.com/searchevents/?text=' + searchText,
(data) => {
setListEvents(data);
setPopupOpen(true);
},
'jsonp',
);
} else {
setPopupOpen(false);
}
}, 200);
}, []);
const handleInputFocus = useCallback((ev) => {
if (ev.target.value.length > 0) {
setPopupOpen(true);
}
}, []);
const handlePageLoading = useCallback((args) => {
const start = formatDate('YYYY-MM-DD', args.viewStart);
const end = formatDate('YYYY-MM-DD', args.viewEnd);
setTimeout(() => {
getJson(
'https://trial.mobiscroll.com/searchevents/?start=' + start + '&end=' + end,
(data) => {
setCalEvents(data);
},
'jsonp',
);
});
}, []);
const handlePopupClose = useCallback(() => {
setPopupOpen(false);
}, []);
const handleEventClick = useCallback((args) => {
setSelectedEvent([args.event]);
setPopupOpen(false);
calInst.current.navigateToEvent(args.event);
}, []);
const searchInputRef = useCallback((input) => {
setSearchInput(input && input.nativeElement);
}, []);
const customHeader = useCallback(
() => (
<>
<CalendarNav />
<div className="mds-search-bar mbsc-flex-1-0">
<Input
autoComplete="off"
inputStyle="box"
placeholder="Search events"
startIcon="material-search"
ref={searchInputRef}
onChange={handleInputChange}
onFocus={handleInputFocus}
/>
</div>
<CalendarPrev />
<CalendarToday />
<CalendarNext />
</>
),
[handleInputChange, handleInputFocus, searchInputRef],
);
return (
<>
<Eventcalendar
data={calEvents}
ref={calInst}
renderHeader={customHeader}
selectedEvents={selectedEvent}
selectMultipleEvents={true}
view={calView}
onPageLoading={handlePageLoading}
/>
<Popup
anchor={searchInput}
contentPadding={false}
display="anchored"
focusElm={searchInput}
focusOnOpen={false}
focusOnClose={false}
isOpen={isPopupOpen}
scrollLock={false}
showArrow={false}
showOverlay={false}
width={400}
onClose={handlePopupClose}
>
<Eventcalendar
className="mds-search-results"
data={listEvents}
showControls={false}
view={listView}
onEventClick={handleEventClick}
/>
</Popup>
</>
);
}
export default App;
import {
CalendarNav,
CalendarNext,
CalendarPrev,
CalendarToday,
Eventcalendar,
formatDate,
getJson,
Input,
MbscCalendarEvent,
MbscEventcalendarView,
MbscEventClickEvent,
MbscPageLoadingEvent,
Popup,
setOptions ,
} from '@mobiscroll/react';
import { ChangeEvent, FC, useCallback, useMemo, useRef, useState } from 'react';
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
});
const App: FC = () => {
const [calEvents, setCalEvents] = useState<MbscCalendarEvent[]>([]);
const [isPopupOpen, setPopupOpen] = useState<boolean>(false);
const [listEvents, setListEvents] = useState<MbscCalendarEvent[]>([]);
const [searchInput, setSearchInput] = useState<HTMLElement>();
const [selectedEvent, setSelectedEvent] = useState<MbscCalendarEvent[]>([]);
const calInst = useRef<Eventcalendar | null>(null);
const timer = useRef<ReturnType<typeof setTimeout>>(undefined);
const calView = useMemo<MbscEventcalendarView>(() => ({ agenda: { type: 'month' } }), []);
const listView = useMemo<MbscEventcalendarView>(() => ({ agenda: { type: 'year', size: 5 } }), []);
const handleInputChange = useCallback((ev: ChangeEvent<HTMLInputElement>) => {
const searchText = ev.target.value;
clearTimeout(timer.current);
timer.current = setTimeout(() => {
if (searchText.length > 0) {
getJson(
'https://trial.mobiscroll.com/searchevents/?text=' + searchText,
(data: MbscCalendarEvent[]) => {
setListEvents(data);
setPopupOpen(true);
},
'jsonp',
);
} else {
setPopupOpen(false);
}
}, 200);
}, []);
const handleInputFocus = useCallback((ev: ChangeEvent<HTMLInputElement>) => {
if (ev.target.value.length > 0) {
setPopupOpen(true);
}
}, []);
const handlePageLoading = useCallback((args: MbscPageLoadingEvent) => {
const start = formatDate('YYYY-MM-DD', args.viewStart!);
const end = formatDate('YYYY-MM-DD', args.viewEnd!);
setTimeout(() => {
getJson(
'https://trial.mobiscroll.com/searchevents/?start=' + start + '&end=' + end,
(data: MbscCalendarEvent[]) => {
setCalEvents(data);
},
'jsonp',
);
});
}, []);
const handlePopupClose = useCallback(() => {
setPopupOpen(false);
}, []);
const handleEventClick = useCallback((args: MbscEventClickEvent) => {
setSelectedEvent([args.event]);
setPopupOpen(false);
calInst.current?.navigateToEvent(args.event);
}, []);
const searchInputRef = useCallback((input: Input) => {
setSearchInput(input && input.nativeElement);
}, []);
const customHeader = useCallback(
() => (
<>
<CalendarNav />
<div className="mds-search-bar mbsc-flex-1-0">
<Input
autoComplete="off"
inputStyle="box"
placeholder="Search events"
startIcon="material-search"
ref={searchInputRef}
onChange={handleInputChange}
onFocus={handleInputFocus}
/>
</div>
<CalendarPrev />
<CalendarToday />
<CalendarNext />
</>
),
[handleInputChange, handleInputFocus, searchInputRef],
);
return (
<>
<Eventcalendar
data={calEvents}
ref={calInst}
renderHeader={customHeader}
selectedEvents={selectedEvent}
selectMultipleEvents={true}
view={calView}
onPageLoading={handlePageLoading}
/>
<Popup
anchor={searchInput}
contentPadding={false}
display="anchored"
focusElm={searchInput}
focusOnOpen={false}
focusOnClose={false}
isOpen={isPopupOpen}
scrollLock={false}
showArrow={false}
showOverlay={false}
width={400}
onClose={handlePopupClose}
>
<Eventcalendar
className="mds-search-results"
data={listEvents}
showControls={false}
view={listView}
onEventClick={handleEventClick}
/>
</Popup>
</>
);
};
export default App;
.mds-search-bar .mbsc-textfield-wrapper {
max-width: 400px;
margin: 8px auto;
}
.mds-search-bar .mbsc-textfield.mbsc-ios-dark {
background: #313131;
}
.mds-search-results .mbsc-calendar-wrapper {
margin-top: -1px;
}