Does anyone know how to modify search results before they are rendered when the modification depends on data returned from an async request?
I have a requirement to filter some search results according to only show results from sites that the user is following.
So far I have done this by calling some JavaScript from my display template which iterates through the page of results and removes whichever are not amongst the users followed sites (which I have retrieved with the SocialFollowingManager).
This approach works but it does cause some problems around the results count and paging and I would much prefer to remove the unwanted result rows from the result set before they are rendered to the page.
I can do this by modifying the results in ctx.ListData.ResultTables[0].ResultRows but unfortunately by the time I have retrieved the data I need to do the filtering the page has loaded and the results have rendered.
Is there a way I can hold the rendering of the display template back while I wait for the async request to complete?
I tried using OnPreRender but even though the process was kicked off before the render began it still didn't work because the page loaded before the async call returned. I also tried requesting the data with a non-async call (just ExecuteQuery) but it seems that this isn't possible (see http://ift.tt/1ybSlBD).
Or is there just a better way of doing this altogether?

0 commentaires:
Enregistrer un commentaire