reactjsreactivesearch

How to display detail page from search results in ResultCard?


Preconditions: React application using appbaseio/reactivesearch

Problem: I am trying to open a simple detail page in the same window (e.g. as a popup window triggered via onclick handler) when I click on a search result. Search results are being displayed by the ResultCard component. Anybody had a similar issue and solved it?

I see there is the url parameter (here: "profile") in the ResultCard component, but it just redirects to the specified url in another tab window.

import {ReactiveBase, DataSearch, ResultCard} from 
appbaseio/reactivesearch";

// ...some more code

<div className="container">
// connector to appbase.io
<ReactiveBase
  app="myapp"
  credentials="xxx"
  theme={{
    primaryColor: "#ffe067"
  }}
>
// search bar
<DataSearch
    componentId="SearchSensor"
    dataField={["gebot_name", "info"]}
    className="search"
/>
// display search results in a list with title and description
<ResultCard
    className="right-col"
    componentId="SearchResult"
    size={10}
    onData={data => ({
      title: data.gebot_name,
      description: data.description,
      url: "profile"
    })}
    react={{
      and: ["SearchSensor"]
    }}
/>
</ReactiveBase>
</div>

Solution

  • So to what I understand from your question you want to display a Modal when clicking on result item and show all the details.

    If this is the case you can use ReactiveList and render the data according to your choice. For eg:

    In v2:

    <ReactiveList
       ...
       onData={ res => (
            <div onClick={() => this.handleModal(res)} >{Content}</div>
         )
       }
    />
    

    With this.handleModal you can handle the Modal and display the data.

    In v3

    <ReactiveList
       ...
       renderItem={ res => (
            <div onClick={() => this.handleModal(res)} >{Content}</div>
         )
       }
    />
    

    Check documentation here:

    For v3: https://opensource.appbase.io/reactive-manual/result-components/reactivelist.html

    For v2: https://opensource.appbase.io/reactive-manual/v2/result-components/reactivelist.html