SharePoint Online search customization with SPFx
-
08-02-2021 - |
Question
I am planning to develop a SPFx WebPart for SharePoint online search, this should be exactly the way we used to customize the display template in SharePoint On-Premise search, could someone please give me some references or examples to start with. Thank you!!!
Solution
As mentioned in the comment, you can use the SharePoint Modern Search web part. You can download the package from this url: https://github.com/microsoft-search/pnp-modern-search/releases
Once you deploy the solution, it will provide you with few web parts (6 of them), for example, you can add the Refiners web part and it will provide you with a dropdown list for all the managed properties available for you to filter (you'll need to have the managed properties ready to be used):
You can connect it to the search results web part that comes with the solution using a web part property as well:
On the search results web part, you can filter it the way you want. You can also choose one of the predefined templates available based on the result type you're getting:
or you can edit the HTML that's generated through the way you want by having a custom template: