No Preview

Sorry, but you either have no stories or none are selected somehow.

If the problem persists, check the browser console, or the terminal you've run Storybook from.

Search Pagination

A simple pagination component to navigate through search results via pages.

Properties

Property NameDescriptionTypeRequired
currentPageThe current page number.numbertrue
totalPagesThe total number of pages.numbertrue

Example

// First, import what we need from React SDK.
import { PageController, WidgetDataType, useSearchResults, widget } from '@sitecore-search/react';

// Import the component generated by the CLI.
import SearchPagination from '@/components/SearchPagination';

const {
  state: {page, itemsPerPage, },
  queryResult: { data: {
    content = [],
    total_item: totalItems = 0,
  } = {} },
} = useSearchResults({
  state: {
    page: 1,
    itemsPerPage: 24,
  },
});
const totalPages = Math.ceil(totalItems / itemsPerPage);
return (
  <>
    <ol>
      {content?.map((content, index) => (
        <li className="fade">
          #{(index + 1).toString().padStart(2, '0')}{content.title}
        </li>
      ))}
    </ol>
    <SearchPagination currentPage={page} totalPages={totalPages} />
  </>
);

// Convert the regular component to a compatible widget.
const SearchResultsWrapperWidget = widget(SearchResultsWrapper, WidgetDataType.SEARCH_RESULTS, 'content');

// Then we can use the widget.
function MyApp() {
  return (
    <WidgetsProvider {...CONFIG}>
      <SearchResultsWrapperWidget rfkId="rfkid_7" />
    </WidgetsProvider>
  )
}

Installation

npx sc-search new-component -w -s styled -l typescript -n SearchPagination -o <destination/path>