Development

Adjust the archive control: fix for paging & limit items

Recently I wanted to use Archive control in one of my projects. The requirement of the customer was that they would like to filter news items based on years. Now they have an archive of like six years, so they also wanted to limit these years to show only the two latest years.

Daniel Plomp

May 31st, 2012

Recently I wanted to use the Archive control in one of my projects. The requirement of the customer was that they would like to filter news items based on years. Now they have an archive of like six years, so they also wanted to limit these years to show only the two latest years.

So I ran into some troubles regarding these requirements.

  1. When using a pager on the NewsWidget, the filtering on the year was removed.

  2. I couldn't configure the Archive control to limit the item count

I'll explain how to solve these two issues.

When using a pager on the NewsWidget, the filtering on the year was removed.
To solve this issue it was just a matter of changing the UrlEvaluationMode of the NewsView widget from UrlPath to QueryString. Now the URLs look a bit more unfriendly, but at least you can page through your selection.

I couldn't configure the Archive control to limit the item count
For this issue to solve, I created a new control and inherited it from Telerik.Sitefinity.Web.UI.PublicControls.ArchiveControl.

I created a property to actually let the administrator of the site adjust the limit of the items:

After that I override the DataBindArchiveRepeater method, to adjust the filter to the data source, like this:

I have also overridden the ArchiveRepeaterOnItemDataBound event, but that was just to have some modifications on how the rendering was happening for each item inside the repeater: 

So, with help of Sitefinity Thunder, I added the new control to the toolbox, built my project and the widget now shows the latest 3 years inside the archive control.

Thanks, Boyan Barnev for your support on this.  

All rights reserved © ZimplerApps 2012