Creating an alphabetically organized transformation

Kayla Johnson asked on September 2, 2014 17:15

We're using the Event Document Type and need to create an alphabettically divided list of events (see here http://grab.by/zZrS). I can use the Universal Viewer with an Order By no problem. But my problem comes in with the divider. How can I display the letter of the alphabet before each grouping of events that start with that letter. Also, we need to be able to limit the number of events that display under each letter to about 5. I think I need to use a hierarchical transformation? But I'm not sure, nor do I understand them. All of our events are located in the same hierarchical level.

A. --- 1. Art Class

B. --- 1. Ballet Lesson 2. Boday Works

etc....

Recent Answers


Brenden Kehren answered on September 3, 2014 07:11

A hierarchical viewer will only work if you have a parent/child relationship setup between the letters and the events. In my opinion, its a bit more work to do that than what it's worth.

Simplest thing I can think of is using a Query Repeater and creating a query on the events to get the distinct letters for the events you have in the system.

select distinct UPPER(SUBSTRING(EventName,1,1)) AS [Letter]
from CONTENT_Event

Then inside the transformation for the "letter", you'd have a nested repeater that would get the top N events that have an event name starting with the letter being rendered. Your query repeater transformation might look something like this:

<script runat="server">
    protected override void OnInit(EventArgs e) 
    {
        string letter = ValidationHelper.GetString(Eval("Letter"), ""); // get the current letter being rendered
        if (!string.IsNullOrEmpty(letter))
        {
            // only set and bind the repeater if there's a letter
            rptNested.Where = "EventName LIKE '" + letter + "%'"; 
            rptNested.ReloadData(true);                
        }
    }
</script>

<div>
    <h2><%# Eval("Letter") %>.</h2>
    <hr />
    <cms:CMSRepeater ID="rptNested" runat="server" TransformationName="cms.event.yourtransformation" ClassNames="cms.event" TopN="5" OrderBy="EventDate" />

</div>
0 votesVote for this answer Mark as a Correct answer

Kayla Johnson answered on September 3, 2014 19:34

So I created a repeater with custom query web part. and set the Query name to the query you provided. Not sure if I have to change anything? How do I know what to put for the FROM? I'm just using the CMS.Event Doc type. http://grab.by/A28G

Where does the transformation for the letter go? I try to add New for the "Transformation name:" but I get an error Object reference not set to an instance of an object.. http://grab.by/A28m

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 3, 2014 20:11

Whatever custom query you created on the cms.event would be populated in the first image. In the Query the FROM would be the cms.event objects corresponding table, which I believe is content_event by default.

You'd add the transformation to the cms.event doc type, both of them in fact.

0 votesVote for this answer Mark as a Correct answer

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