0

I have around 20 libraries with about 2.000 files each.

The content is being organized through the use of a Drop Off Library and metadata (Example: Department). This content is being shown and accessed through Content Search Web Parts and this is working great.

Some users are still going into the specific library where the views are Grouped By metadata fields. My issue starts here. They want to see documents Grouped By Contract, that overlays through the different Departments library.

Is there a way I can achieve the same or similar experience using CSWP or another Sharepoint option?

Thank you

2
  • Have you tried Content Query web part? It allows displaying documents from libraries based on a content type. Filters and grouping is also available. – Ahmad Zia Feb 2 '18 at 4:19
  • Thank you for your answer Ahmad. CQWP is not part of the best practices anymore, even for small things it should be avoided specially in SPO as it will impact users to a slower loading page time. For the purposes of this example in particular, the amount of files we are talking about and them being widely spread across different libraries, it will be very slow while heavily taxing the resources. – Yugo Feb 2 '18 at 14:26
0

Update Display Template to achieve the same. Create a new current context ctx variable, and add an grouping object to it. For this approach a control and item display template needs to be created.

Control Template:

<script>
Type.registerNamespace('search.Grouping');

search.Grouping = function() {
    var currentCtx;
    return {
        init: function (currentContext, encodedId) {
            currentCtx = currentContext;

            // Creating a new grouping object
            currentCtx.Grouping = {};

            // Add an on post render callback, this will be excuted when all the results are rendered
            AddPostRenderCallback(currentContext, function() {
                var groupElm = document.getElementById(encodedId);
                search.Grouping.show(groupElm);
            });
        },
        push: function (grouping, content) {
            // Add the markup to the grouping array 
            if (typeof currentCtx.Grouping[grouping] !== "undefined") {
                currentCtx.Grouping[grouping] += content;
            } else {
                currentCtx.Grouping[grouping] = content;
            }
        },
        show: function (groupElm) {
            var groups = currentCtx.Grouping
            // Add the content to the page
            for (var key in groups) {
                groupElm.innerHTML += String.format("<div class='group'><h2 style='color:#000'>{0}</h2>{1}</div>", key, groups[key]);
            }
        }
    }
}();
</script>


<div id="Control_List">

<!--#_
var encodedId = $htmlEncode(ctx.ClientControl.get_nextUniqueId() + "_Grouping");

// Grouping init
search.Grouping.init(ctx, encodedId);

if (!$isNull(ctx.ClientControl) &&
    !$isNull(ctx.ClientControl.shouldRenderControl) &&
    !ctx.ClientControl.shouldRenderControl())
{
    return "";
}
ctx.ListDataJSONGroupsKey = "ResultTables";
_#-->
<div id="_#= encodedId =#_">
    _#= ctx.RenderGroups(ctx) =#_
</div>
</div>

Item Template:[Here we are grouping on the basis of siteTitle]

<mso:ManagedPropertyMapping msdt:dt="string">'Link':'Path','Line 1'{Line 
1}:'Title','Grouping':'SiteTitle'</mso:ManagedPropertyMapping>

and then:

  var line1 = $getItemValue(ctx, "Line 1");
  var grouping = $getItemValue(ctx, "Grouping");
  var linkURL = $getItemValue(ctx, "Link");

 // HTML Markup
     var content = String.format('<div class="cbs-Item"><a class="cbs-
     Line1Link ms-noWrap ms-displayBlock" href="{0}" title="{1}">{1}</a>
     </div>', linkURL, line1);

  // Push the content to the grouping object
  search.Grouping.push(grouping, content);
1
  • Hi Deepmala, thank you for your reply. I saw that it looks exactly like what Amy linked. Although it is nice that results will be ordered by a specific field it does not look at all like the "Library Group By view". What I don't want is people scrolling through hundreds of results until they find the category they are actually looking for. Do you believe this is achievable? (PS: You should give the credits to who made this possible eliostruyf.com/…) – Yugo Feb 2 '18 at 14:29
0

You could add custom code to group results in the content search web part.

For more detailed information, refer to the article below.

Grouping search results with display templates for the CSWP.

https://www.eliostruyf.com/grouping-search-results-with-display-templates-for-the-cswp/

2
  • Hi Amy, thank you for the reply. You have to be careful with this type of replies, as if at any point this is helpful but later on the link is dead, no one would be able to actually know what happened. This being said, although it is nice that results will be ordered by a specific field it does not look at all like the "Library Group By view". What I don't want is people scrolling through hundreds of results until they find the category they are actually looking for. Is this achievable? – Yugo Feb 2 '18 at 14:21
  • Thank you for pointing out, I will pay attention to the issue. – Amy_MSFT Feb 2 '18 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.