For those who want to hide Content Query Web Part when empty, in other words, when it returns not data, this post is for you! The solution won’t require you to dive into XSL world, it’s pure JavaScript. Basically you will drop the code code snippet to your pages and everything will work.
The Content Query Web Part (CQWP) is a great way to query data from other sites and present it inside one page. Content Query Web Part can be used with their default layouts or you can create some if want.
According to a Code Project article: ” This web part is rather nifty and it has many cool features. With the CQWP, you can now control how the content is displayed. We can use html tables to format the display however we wish. This article explains how to customize the CQWP using SharePoint 2010 without any code and deployment. “.
Unfortunatelly, this post may be a little bit outdated because Microsoft reinforces that Content Search Web Part is a better option now. You can check this post when to use the Content Query Web Part or the Content Search Web Part in SharePoint.
Hiding Content Query Web Part via JavaScript
It’s up to you if you want to set this behavior to every page in your Web Site putting the code in a global JS file, or just for an specific one using a Script Editor Web Part to do the trick.
Anyway, hope this script can help you to hide Content Query Web Part when empty. Also you may check other posts related to SharePoint customizations in my blog clicking here.
Leave a Reply