This is a migrated thread and some comments may be shown as answers.

Differiante each alternating item in a MobileListView

3 Answers 250 Views
ListView (Mobile)
This is a migrated thread and some comments may be shown as answers.
Per Lindsø
Top achievements
Rank 2
Per Lindsø asked on 14 Mar 2013, 03:02 PM
Hi,

Can't see "altTemplate" implemented in MobileListView. What is the proper way to give each second row a diffenrent color?

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 18 Mar 2013, 09:01 AM
Hi Per,

I am afraid that the mobile ListView does not support altRowTemplate, however you can easily give each second row a different colour via CSS.
.km-listview > li:nth-child(2n) {
    background-color: #CCCCCC;
}

In case you need a more complex customization, such as displaying different dataItem fields, you may use JavaScript condition inside the mail template. For more information please check the template overview topic.

I hope this will help.

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jim
Top achievements
Rank 1
answered on 07 Mar 2016, 02:58 AM

I have a similar issue, but my listview is the 2nd view on a page that is dynamically created, so I want to do this with jquery.  I tried this:

$('#tasklist-listview li:nth-child(odd)').addClass('myaltclass');

But the class was applied to all li's.  I ran just $('#tasklist-listview li:nth-child(odd)') in the chrome console, and it appeared to return just the alternate li's.    Below is the code I use to create the listview. 

 

$("#tasklist-listview").kendoMobileListView({
        dataSource: dataSource,
        template: kendo.template($("#listviewtemplate").text()),
        headerTemplate: "<h3>#:value#</h3>",
        filterable: {
            field: "Regarding",
            operator: "startswith"
        }
    });

0
Petyo
Telerik team
answered on 09 Mar 2016, 08:14 AM
Hi,

the approach should work in general. Perhaps this is some sort of a timing issue? The jQuery command should be executed after the listview is bound. Another thing which may be a problem in this approach is the filterable - the filtering may leave only certain items, resulting in uneven distribution of alternating items. If possible, please use the CSS-only approach we gave below. 

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
ListView (Mobile)
Asked by
Per Lindsø
Top achievements
Rank 2
Answers by
Alexander Valchev
Telerik team
Jim
Top achievements
Rank 1
Petyo
Telerik team
Share this question
or