[英]Hide / Remove Content Search Webpart when no results returned SharePoint 2013
I'm looking to find a way to hide the whole Content Search webpart (including the webpart title and border area) if there are no results coming back from the query. 如果没有查询返回的结果,我正在寻找一种隐藏整个Content Search Webpart(包括WebPart标题和边框区域)的方法。
What I tried 我尝试了什么
There is this property: "ShouldHideControlWhenEmpty" but it doesn't do anything when there are no results. 有这个属性:“ ShouldHideControlWhenEmpty”,但是在没有结果时它什么也不做。 The webpart is still visible.
Webpart仍然可见。 Webpart has a the Title and the Border around it so when there are no results the title and the border show up with no results.
Webpart周围有一个“标题”和“边框”,因此,如果没有结果,则标题和边框不会显示任何结果。 Like I said I want to hide the whole thing in that case.
就像我说的那样,在这种情况下我想隐藏整个事情。
Wrote a jQuery script that searches for the text "There are no results" message (which comes from the webpart when there are no results) and hides the webpart. 编写了一个jQuery脚本,该脚本搜索文本“无结果”消息(无结果时来自Web部件)并隐藏该Web部件。 However, there is a short flicker once the page loads because the webpart first gets rendered for a split second and then disappears by virtue of my jQuery script - which is not great UI experience.
但是,一旦页面加载,就会出现短暂的闪烁,因为首先通过一秒钟的时间渲染Webpart,然后借助我的jQuery脚本消失了-这不是很棒的UI体验。
So I thought I could extend the OOTB ContentBySearchWebPart and get a hold of some kind property that would get me the result count. 所以我想我可以扩展OOTB ContentBySearchWebPart并获得某种财产的所有权,该财产会让我获得结果计数。 If the results count is 0 simply I would hide the webpart server side.
如果结果计数为0,那么我将隐藏Webpart服务器端。 I looked at the documentation online - nothing I could find that I could leverage.
我在线上查看了文档-我找不到可以利用的文档。 Help?
救命? Thanks!
谢谢!
The option 2 using jquery would be fine, but just flip the approach you are doing now. 使用jquery的选项2可以,但是只需翻转您现在正在使用的方法即可。 Instead of hiding the webpart if its empty , make the webpart hidden by default, and visible only when content is available.
而不是隐藏WebPart(如果它为空),则使WebPart默认情况下是隐藏的,并且仅在内容可用时才可见。 Here is the approach.
这是方法。
This way you will eliminate the Flicking problem with the current approach. 这样,您将消除当前方法中的Flicking问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.