Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Filter a repeater bsaed on categories View modes: 
User avatar
Member
Member
lwhittemore-emh - 6/29/2013 1:39:05 PM
   
Filter a repeater bsaed on categories
Is there a way to filter my content by category?

User avatar
Kentico Support
Kentico Support
kentico_romank - 6/29/2013 10:41:21 PM
   
RE:Filter a repeater bsaed on categories
Hi,

To filter content you can use standard repeater with defined where condition where you will specify required category.

For example
DocumentID IN (SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID IN (SELECT CategoryID FROM CMS_Category WHERE CategoryName LIKE 'Technology'))

Best Regards,
Roman Konicek

User avatar
Member
Member
kyle.shankin-gmail - 8/9/2013 3:05:42 PM
   
RE:Filter a repeater bsaed on categories
Is there a way to set this up where you can select your category via dropdown to filter the data?

Specifically, I have a custom data type that utilizes a two-level category system (categories and sub categories). I have a functional basic repeater reading from a document data source, but would like to be able to filter these items based off the various categories.

Thanks in advance for any help

User avatar
Member
Member
kentico_sandroj - 8/10/2013 12:38:54 PM
   
RE:Filter a repeater bsaed on categories
Hello,

You can add a dropdown in the Content Before property of the repeater and use javascript to add a querystring to the URL, then use a querystring macro in the WHERE condition to filter.

Here is an example:
<script type="text/Javascript">        
function report(SelectedCategories)
{
window.location.search = 'cat='+SelectedCategories;
}
</script>
<table>
<tr>
<div><h1>select Category</h1>

<select onchange="report(this.value)" name="FilterCategory">
<option value="All">All</option>
<option value="Cat1">Cat1</option>
<option value="Cat2">Cat2</option>
</select>
</div>
</tr>
</table>

Please let me know if you have any questions.

Regards,
Sandro

User avatar
Member
Member
kyle.shankin-gmail - 8/12/2013 7:34:29 AM
   
RE:Filter a repeater bsaed on categories
Thanks Sandro,

I'll be trying this out today and will let you know how it goes.

User avatar
Member
Member
kyle.shankin-gmail - 8/12/2013 1:20:17 PM
   
RE:Filter a repeater bsaed on categories
Thanks again Sandro,

I've read through the querstring macro doc that you linked to, and I know where the "WHERE" input filter is located at, but I do not understand how I am supposed to know what the querystring key is and how I am meant to put it in the "WHERE" input filter. Could you please help with that?

I have used an altered version of the code mentioned above to populate the filter:
<script type="text/Javascript">        
function report(SelectedCategories)
{
window.location.search = 'cat='+SelectedCategories;
}
</script>
<table>
<tr>
<div><h1>Select Category</h1>
<select onchange="report(this.value)" name="FilterPrimaryCategory">
<option value="All">View All</option>
{%foreach(category in SiteObjects.Categories){ ResolveMacros("\r\n {%if (category.CategoryLevel ==0) { %}
</select>

Am I meant to just put {%cat%} or {%category%} in the WHERE filter?

User avatar
Member
Member
kentico_sandroj - 8/12/2013 2:24:03 PM
   
RE:Filter a repeater bsaed on categories
Hello,

The querystring will be whatever you put in the javascript function, in this case it is cat, so the querystring would be {%cat%}. You would place the {%cat%} querystring in the WHERE condition. Please let me know if it works as expected.

Regards,
Sandro

User avatar
Member
Member
kyle.shankin-gmail - 8/12/2013 2:40:46 PM
   
RE:Filter a repeater bsaed on categories
Hi Sandro,

I tried what you have suggested. The only thing that happens when an item is selected is a page refresh.

User avatar
Member
Member
kentico_sandroj - 8/13/2013 6:38:36 PM
   
RE:Filter a repeater bsaed on categories
Hello,

The issue is likely in the custom options as I have tested this example and it worked for me. Do you get the value that you need in the querystring? Could you try the hard-coded values just to test?

User avatar
Member
Member
kyle.shankin-gmail - 8/15/2013 10:04:40 AM
   
RE:Filter a repeater bsaed on categories
Hi Sandroj,

I've made some progress. Turns out that part of my issue was that I was using a Document Data Source web part which was not necessary.

After getting rid of the unnecessary web part and re-configuring the repeater, I am able to filter the data by manually selecting the category under the filter section of the repeater. However, when I enter {%cat%} in the WHERE condition, I receive a SQL error when I select a category after the page initially loads:

caused exception: An expression of non-boolean type specified in a context where a condition is expected, near ')'.

do you have any suggestions?

User avatar
Member
Member
kyle.shankin-gmail - 8/15/2013 1:25:42 PM
   
RE:Filter a repeater bsaed on categories
Hello again Sandroj,

I found my own error and was able to get the filter working, thank you very much for your help!

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 8/15/2013 2:31:21 PM
   
RE:Filter a repeater bsaed on categories
Please, did you notice his signature? His name is Sandro and not Sandroj :)

User avatar
Member
Member
kyle.shankin-gmail - 8/15/2013 2:42:32 PM
   
RE:Filter a repeater bsaed on categories
Sorry, I did not notice the signature. Just the username...thanks for pointing it out.