SearchstaxSortingWidget for React and Next.js


The SearchStax Site Search solution offers a sorting widget for your React or Next.js custom search page.

The SearchstaxSortingWidget displays sorting options for search results.

Usage

<SearchstaxSortingWidget />

searchSortingTemplate

Renders custom sorting UI.

Receives:

  • sortingData – Sorting data
  • orderChange – Handles sorting order change
  • selectedSorting – Current sorting

Example

function searchSortingTemplate(
    sortingData: null | ISearchstaxSearchSortingData,
    orderChange: (value: string) => void,
    selectedSorting: string
  ) {
    return (
      <>
        {sortingData && sortingData?.searchExecuted && sortingData?.hasResultsOrExternalPromotions && (
          <div className="searchstax-sorting-container">
            <label className="searchstax-sorting-label" htmlFor="sort-by">
              Sort By
            </label>
            <select
              id="searchstax-search-order-select"
              className="searchstax-search-order-select"
              value={selectedSorting}
              onChange={(e) => {
                orderChange(e.target.value);
              }}
            >
              <option value=""> Relevance </option>
              <option value="date desc"> Newest Content </option>
              <option value="date asc"> Oldest Content </option>
            </select>
          </div>
        )}
      </>
    );
  }
  <SearchstaxSortingWidget searchSortingTemplate={searchSortingTemplate}></SearchstaxSortingWidget>

Questions?

Do not hesitate to contact the SearchStax Support Desk.