0

In SharePoint Online I want to sort search result by multiple fields for that I want to add sort dropdown in Content Search Web Part

enter image description here?

  • Do you mean you need multiple sort drop downs? – Gintas K May 4 '16 at 10:35
  • You would get the sorting by default in a Search Results Webpart. Any reason you can not use that? If not, use it instead :) – Robert Lindgren May 4 '16 at 10:46
  • Requirement is to use only Content Search webpart... – Sarika Koli May 4 '16 at 10:51
0

For Content Search WebPart (CSWP), you need to develop this feature as part of the display template. In the control template, you can add the dropdown with the relevant sort values. In the dropdown change event, change the Content Search WebPart's query with the appropriate sorting (based on managed property) by using Srch.U.fillKeywordQuery function.

Sample code - dynamically changes the result source

if (typeof Srch.U.fillKeywordQuery !== 'undefined') {
    // Override the fillKeywordQuery function
    var originalFillKeywordQuery = Srch.U.fillKeywordQuery;
    // Override the default fillKeywordQuery function
    Srch.U.fillKeywordQuery = function(query, dp) { 
        console.log(dp.get_id());
        dp.set_sourceID('70949b02-0f2c-4026-9c4f-c9d6e0023aa4');
        // Call the default function to go further with the query processing
        originalFillKeywordQuery(query, dp);
    };
}

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.