Installation and deployment
Version 7.x > Installation and deployment > Web part repeater View modes: 
User avatar
Member
Member
pavel.1991-tut - 3/29/2013 9:33:06 AM
   
Web part repeater
I made a new document type, added fields to this document type. Then, I created some pages with this document type and I filled the fields. Then I created transformation for this document type. Then I used repeater web part and this transformation to show data from my pages. All is good, but I need that the last and first data block on the page have another transformation(another html around data). How can I do this?

User avatar
Member
Member
kentico_sandroj - 3/29/2013 3:35:50 PM
   
RE:Web part repeater
Hi Pavel,

In order to affect a specific item in a transformation, it is necessary to use hierarchical transformations. Hierarchical transformations are basically nested transformation which allow you to target a specific item using a sub-transformation. These are the available options:

•Item transformation - applied to all displayed items that are not covered by a specialized transformation type (e.g. alternating items, first items etc.).

•Alternating item transformation - applied to items that have an even position in the listing order. Every level in the hierarchy has its own separate alternation pattern.

•First item transformation - applied to the first item on every level in the hierarchy. Only works for levels that contain more than one item.

•Last item transformation - applied to the last item on every level. Only works for levels that contain more than one item.

•Header transformation - rendered at the beginning of every level (before the first item on the level). These transformations provide a convenient way to visually separate or style individual levels.

•Footer transformation - rendered at the end of every level (after the last item on the level). Can be used to close encapsulating elements from the Header.

•Single item transformation - applied in cases where there is only one item on a level in the hierarchy.

•Separator transformation - rendered between items on the same level. It is not placed between items on different hierarchy levels (i.e. between a parent item and its child).

•Current item transformation - applied to the currently selected item (i.e. the document that is being viewed). Please note that it is always necessary to specify a Document type (or types) for this kind of transformation.

If there are multiple sub-transformations being applied to one item, only the highest priority transformation type will be used:

1.Current item (top priority)
2.First/Last/Single item
3.Alternating item
4.Item

The following link is to an article in the developer's guide that explains how to configure and use hierarchical transformations: Hierarchical transformations

Please let me know if you need any additional clarification on this. Thank you!

Best Regards,
Sandro Jankovic

User avatar
Kentico Legend
Kentico Legend
Accepted solutionAccepted solution
Brenden Kehren - 4/3/2013 10:16:19 AM
   
RE:Web part repeater
No need to complicate it too much, you can use the to items below to determine first and last.
// gives you the total count of items 
DataRowView.DataView.Count
// gives you the current index (zeor based)
DataItemIndex
<%# (DataItemIndex == 0 ? "<div class='first'>" : ((DataRowView.DataView.Count - 1) == DataItemIndex ? "<div class='last'>" : "<div class='item'>))

User avatar
Member
Member
pavel.1991-tut - 4/4/2013 8:28:26 AM
   
RE:Web part repeater
Thanks, it is very good. But I have one more question about this. I made a document type, then created 10 pages using this document type. Then I use repeater to display data from these pages. And I need that data from every 2 pages be wrapped by div with my css classes. For example their transformation:
<div class="col">
<%# Eval("data") %>
</div>

and I need to get the next output code:
<div class="row">
<div class="col">
data
</div>
<div class="col">
data
</div>
</div>
<div class="row">
<div class="col">
data
</div>
<div class="col">
data
</div>
</div>

Do you understand what I mean? Output of every two transformations must be wrapped tags with classes which I need.

How to do this?

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 4/4/2013 3:58:16 PM
   
RE:Web part repeater
Use Mod in C#.
(DataItemIndex / 2) % 2) == 1 // write the <div>
This render render the results of:
0
0
1
1
0
0
1
1
0
0
Using the example I gave you above you should be able to implement this as well.

User avatar
Member
Member
pavel.1991-tut - 4/5/2013 3:14:07 AM
   
RE:Web part repeater
Unfortunately I can not understand. If I correctly understand, transformation generates html with data from one page. If I write any C# or html code in transformation, it will work within only one page. I mean, for example, I can find out which page data is used from, using DataItemIndex. And after this I can wrap any divs data from this page. But it will be wrapped data only from one page. I can not wrap data from two or more pages within one transformation. Am I right?

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/5/2013 4:28:00 AM
   
RE:Web part repeater
Hi,

Transformation (ASCX) is basically a control that displays some data. It generates the html with data from one record at a time, but you can also find out the index (number) of the item among all items rendered by a repeater, so as FroggyEye suggests, you can use a condition with modulo operation to identify odd and even records. You can then render the leading or closing DIV.
Just to correct the condition - if you wish to wrap two records in one div as you wrote, you can use the condition for the odd record by just % 2, you don't have to divide it by 2 first:
<%# ((DataItemIndex % 2) == 1)?"<div class=\"row\">":"" %>  // write leading DIV for odd record
<div class="col">
<%# Eval("data") %>
</div>
<%# ((DataItemIndex % 2) == 1)?"":"</div>" %> // write closing DIV for even record, you may need to add a test for last item to add closing div even if it was an odd record

The same thing can be more simple using the hierarchical transformations, as you can directly use the "alternating" transformation for even rows and you don't have to use the conditional expression. Moreover, you can solve the last non-pair record closing DIV easily by using "Last item transformation".

You may also consider using DataList web part or control, which allows to set number of records per row.

Hope this will be helpful.

Regards,
Zdenek

User avatar
Member
Member
andreycoman-yahoo - 8/30/2013 9:35:57 AM
   
RE:Web part repeater
Hi,
I have a question regarding hierarchical transformation: Can I get the position of level 0 elements without including the positions of other elements on other levels?
For example I have this structure:
level 0
level 1
level 1
level 0

If I use in level 0 item transformation "DataItemIndex" it will return (0,3), but I want (0,1).
Is this possible or I have to use javascript to change my level 0 items ascendenting?

Thank you,
Andrei

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 9/1/2013 1:45:22 PM
   
RE:Web part repeater
Hi Andrei,

Do you mean to order the items by levels? Like to show all from level 0, then from level 1... or do you want just the DataItemIndex to reflect the hierarchy and not the visual order?

Any further details could help...

Thank you in advance for information.

Regards,
Zdenek

User avatar
Member
Member
andreycoman-yahoo - 9/2/2013 1:33:06 AM
   
RE:Web part repeater
Hi Zdenek,
I want to reflect the hierarchy. The first level 0 item to have the id 0, the second level 0 item to have the id 1, and so on... is it possiblde with DataItemIndex?

Thank you,
Andrei

User avatar
Member
Member
andreycoman-yahoo - 9/4/2013 2:36:54 AM
   
RE:Web part repeater
Hi,
Also I want to display using the hierarchical viewer only the first 2 elements (level 0) with all their child nodes.
Can please someone help me solve this. I'm new using this kind of transformation...

Thank you,
Andrei

User avatar
Member
Member
andreycoman-yahoo - 9/13/2013 4:19:08 AM
   
RE:Web part repeater
Hi,
It is possible when I show the elements into an hierarchical transformation to limit the numbers of items of each level? I've tried using "NodeOrder" but it works partially...

do you have any other ideas? Or it's not possible and I have to use repeaters?

Thank you,
andrei

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 9/24/2013 10:17:47 PM
   
RE:Web part repeater
Hi Andrei,

Sorry for not getting back to you earlier. Have you found solution to your questions?
As for limiting the number of items, have you tried using Top N together with the NodeOrder? Or how exactly have you tried to use it? NodeOrder tells the order of the node in a given level in the content tree...

Thank you in advance for information.
Regards,
Zdenek