Filter on custom modules

Posted by Community Admin on 04-Aug-2018 08:29

Filter on custom modules

All Replies

Posted by Community Admin on 18-Apr-2012 00:00

Hello,

I have made a custom module, while looking at the reference code I found how to filter based on the URL name.

DynamicContent produktenNachLokationen = dynamicModuleManager.GetDataItems(produktenNachLokationType).Where("UrlName = \"" + locationName + "\"").First();

What I would like to do now is filter directly on a custom classification (name; Locations, type; Simple list) is this also possible?

Thanks,
Rick

Posted by Community Admin on 19-Apr-2012 00:00

Hi Rick - 

You need to get get the ID of the Taxonomy you wish to retrieve your records by and pass that in with your query. Here is an example:

1.var taxonomy = TaxonomyManager.GetManager().GetTaxonomies<FlatTaxonomy>().Where(
2.                    t => t.Name == "Region").Single().Taxa.Where(
3.                        t => t.Title == this.Region).SingleOrDefault();
1.DynamicContent produktenNachLokationen = dynamicModuleManager.GetDataItems(produktenNachLokationen)
2.    .Where(x => x.UrlName == new Lstring(locationName) &&
3.           x.GetValue<IList<Guid>>("Region").Equals(taxonomy.Id)).FirstOrDefault();

You'll also need to include the Taxonomy namespaces and the GetValue extension which is located in Telerik.Sitefinity.Model.

1.using Telerik.Sitefinity.Taxonomies;
2.using Telerik.Sitefinity.Taxonomies.Model;
3.using Telerik.Sitefinity.Model;

Though, I haven't used any modules built with the module builder. All my modules are custom. But I'd venture to guess this is the same either way. Hope this helps you out!

Cheers,
Josh

Posted by Community Admin on 21-Apr-2012 00:00

Hi Josh,
Thanks for helping! Your code seems to work just fine. The only thing is, the result set contains all module items twice! Any idea why that is?
Kind regards, Tys

Posted by Community Admin on 21-Apr-2012 00:00

Hi Tys - 

No worries! It's pulling all the versions of the content. Try filtering by the live items. The where clause would look like this:

.Where(x => x.UrlName == new Lstring(locationName) && x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)

Cheers,
Josh

Posted by Community Admin on 21-Apr-2012 00:00

Ah, forgot about that. Thanks! Now it works totally as it should!

Posted by Community Admin on 21-Apr-2012 00:00

Ha! No worries. Glad it's working for ya!

This thread is closed