Filter repeater 'results'

Jon White asked on November 28, 2016 15:00

Hi all,

Is there a way to filter custom page types when you're displaying the items using a repeater?

So say I have a list of staff displayed using a repeater and I want some filtering such as a dropdown field that allows to to select which department they work in (generated dynamically).

This would then refresh and display only that department.

Or this could be used to 'order by' date added, a to z etc...

Can this be done easily with a repeater or does it need to be a 'search on page load' combined with search filters instead?

I saw an article using product filter to achieve what i'm talking about, but I'm not filtering products: Can this be modfiied for custom page types?

Any help is much appreciated as always,

Thanks Jon

Correct Answer

Brenden Kehren answered on November 28, 2016 20:22

You can use the simple Smart Search Filter webpart and attach it to a Smart Search Results repeater. In the filter choose a Dropdown as the filter type. Then create a new query which gets the categories and enter this as your text:

SELECT 'DocumentCategoryIDs', CategoryID, CategoryDisplayName FROM CMS_Category WHERE ##WHERE## ORDER BY ##ORDERBY##

Then in the WHERE enter this

CategoryEnabled = 1 and CategoryNamePath like '/YourParentCategoryName/%' and CategoryUserID is null AND (NOT EXISTS(SELECT CategoryID FROM CMS_Category AS pc WHERE (pc.CategoryEnabled = 0) AND (CMS_Category.CategoryIDPath like pc.CategoryIDPath+'/%')))

In the OrderBY set it like so:

CategoryLevel, CategoryOrder, CategoryDisplayName

Filter clause should equal "Must"

Check the "filter is conditional" box.

In the Smart Search Results repeater select a smart search index, if you don't have one, create one. Then make sure Block field-only search is unchecked, Search on each page load is checked, Search text required is unchecked and assign a transformation name.

This should get you what you need without needing to write any code.

1 votesVote for this answer Unmark Correct answer

Recent Answers

Jan Hermann answered on November 28, 2016 15:25

Yes, the filtering wold be over ClassName column that is present there by default (if you don't exclude it from Columns property).

1 votesVote for this answer Mark as a Correct answer

Laura Frese answered on November 28, 2016 18:49 (last edited on November 28, 2016 18:50)

There are two ways to create filters.

1) programmatically which I consider to be best practice

2) Using querystring parameters and a querystring macro the where condition in the repeater. FOr example, you have 2 transformations - 1 transformation for the repeater that will repeat only the dropdownlist items, and one transformation for the list of results. If necessary, you can create a custom query to select distinct myfield from mycustom_pagetype and use a custom query repeater to list those results

Then you use jquery to reload the page with the querystring param

 $("#drop").change(function () {
        var q = this.value;
        window.location = '/mypage?somekey=' + q

Then in the repeater where field you add the macro

MyField = {% somekey %}

This gets complicated if your querystring is a string instead of an int. Take a look at my blog post on filtering to ensure you do it securely

OR you could use the category selector field control, create the departments as categories, and in the repeater you can enter the querystring macro in the category field.

You can use these querystring macros in teh order by field in the repeater too

1 votesVote for this answer Mark as a Correct answer

Jon White answered on December 6, 2016 18:43 (last edited on December 7, 2016 12:22)

Hi all,

Thanks, looks like it's sorted with your help


0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.