jQuery with ASP.NET

Building rich UI with jQuery and ASP.NET

Easy Client Side Repeater with jTemplates Part 3

without comments


This is the third post in “Easy Client Side Repeater with jTemplates” series. Just to recap quickly – last two posts were about:

ASP.NET developers when asked about the repeater they naturally see something like this:

<asp:Repeater ID="rptSomeRepeater" runat="server">
    <HeaderTemplate></HeaderTemplate>
    <ItemTemplate></ItemTemplate>
    <AlternatingItemTemplate></AlternatingItemTemplate>
    <FooterTemplate></FooterTemplate>
</asp:Repeater>

In the previous posts I have shown how you can represent all Repeater’s templates in jTemplates. You will find there details regarding all the templates except of the one (two actually) which are needed to achieve effect like this:

Chalange here is to set different CSS class for odd and even rows. This kind of effect is easy to implement with standard server side ASP.NET Repeater by using ItemTemplate and AlternatingItemTemplate. So how it can be reproduced with jTemplates and client side repeater?

ItemTemplate and AlternatingItemTemplate with jTemplates

Here is a small modification to the code from previous parts which is doing the trick:

{#foreach $T.d as record}
<tr class="{#cycle values=['odd','even']}">
  <td><a href="{$T.record.WebSite}">{$T.record.Name}</a></td>
  <td><a href="mailto:{$T.record.Organizer.Email}">{$T.record.Organizer.Name}</a></td>
  <td>{$T.record.Venue.Name}</td>
</tr>
{#/for}

Essential part of the above example, and the only change, is this line: class=”{#cycle values=['odd','even']}”. This part makes sense because it’s within {#foreach} … {#/for} block. It works in a way that for the first item on the list jTemplates will take first item from {#cycle} values – in our case – ‘odd’. For the second item – jTemplates will take second element from the list – ‘even’. And for third it will start from the begining.

Final HTML code will look like this:

Questions? Leave a comment!

VN:F [1.9.20_1166]
Rating: 10.0/10 (2 votes cast)
Easy Client Side Repeater with jTemplates Part 3, 10.0 out of 10 based on 2 ratings

Written by admin

April 6th, 2011 at 5:02 pm

Leave a Reply