简体   繁体   English

没有结果返回SharePoint 2013时隐藏/删除内容搜索Webpart

[英]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 我尝试了什么

  1. 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. 就像我说的那样,在这种情况下我想隐藏整个事情。

  2. 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体验。

  3. 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. 这是方法。

  1. Add a Content Editor / Script Editor webpart with CSS code that hides(remember just mark display none / visible false, dont remove) the Content Search Webpart by default. 默认情况下,添加带有CSS代码的Content Editor / Script Editor Webpart,该CSS隐藏(请记住仅将display标记为none / visible false,不要删除)。 Place the styling code above the Content search webpart to ensure when the page loads the Content search Webpart is not visible. 将样式代码放置在“内容搜索” Web部件上方,以确保页面加载“内容搜索” WebPart时不可见。
  2. During pageload check if the Content search webpart contains result , if the webpart contains result , then make the webpart visible. 在页面加载期间,检查Content search Webpart是否包含result,如果Webpart包含result,则使该Webpart可见。 Here you will search for the text "There are no results" message, if its present you do nothing , else you make the webpart visible as it means there are search results available. 在这里,您将搜索文本“没有结果”消息,如果该消息不存在,则什么也不做,否则使Web部件可见,因为这意味着有可用的搜索结果。

This way you will eliminate the Flicking problem with the current approach. 这样,您将消除当前方法中的Flicking问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM