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

ClientTemplate with collection inside

5 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ronald
Top achievements
Rank 1
Ronald asked on 13 Aug 2010, 08:39 AM
Hi

I have defined a ClientTemplate which needs to display an employee and its roles as a list of items inside a single column.

Take following example:

person.cs:
public class Person
{
    public Guid Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    
public string[] Roles { get; set; }
}

The grid looks like this:
<%= Html.Telerik().Grid<Person>()
    .Name("Employees")
    .DataBinding(dataBinding => dataBinding.Ajax()
        .Select("Employees", "Persons"))
    .Columns(columns =>
    {
        columns.Bound(e => e.Id);
    })
    .DetailView(dv => dv.ClientTemplate(
        "Name: <#= LastName #>, <#= FirstName #><br />" +
        "Roles: <ul>" +
            /* Person.Roles comes here: "<li><#= Roles[i] #></li>"
        "</ul>"
    ))
%>

Is there a way to have the roles op the employee displayed as an list inside the same column?


Kind regards,
Ronald Anthonissen

5 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 13 Aug 2010, 08:57 AM
Hello Ronald,

You can embed executable code in your client template like this:

ClientTemplate("Roles: <ul>" +
"<# for (var i = 0; i < Roles.length; i++) {" +
"#> <li><#= Roles[i] #></li> <#" +
"} #>" +
"</ul>")


Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ronald
Top achievements
Rank 1
answered on 13 Aug 2010, 09:03 AM
Yes, it works!

Many thanks!


Kind regards,
Ronald Anthonissen
0
Pedro
Top achievements
Rank 1
answered on 17 Aug 2010, 03:32 PM
Hi

Is it possible to filter this ClientTemplate client side ?

Something on the lines of

var grid = $('#Employees').data('tGrid');
grid.filter("substringof(Roles['All'],'Administrator')");

Where "All" iterates trough all the roles of that Employee.

Best Regards,
Pedro Máximo
0
Philip
Top achievements
Rank 1
answered on 13 Nov 2011, 11:32 PM
Please explain how one would write a for loop in a client row or column template in Razor.
Not just a case of tweaking the syntax of the aspx example above it seems.
Thanks.
0
Ganesh Jagdale
Top achievements
Rank 1
answered on 21 Sep 2012, 02:05 PM
Hi ,
 If anyone please help me out.

ClientTemplate("Roles: <ul>" +
"<# for (var i = 0; i < Roles.length; i++) {" +
"#> <li><#= Roles[i] #></li> <#" +
"} #>" +
"</ul>")


How to create variable in client Template like string s = Roles[i]. I need this because i want some operation on string the binding property comes as quoma sepetated and I want to seprate out each string.

Thanks In advance.

Thanks,
Ganesh
Tags
Grid
Asked by
Ronald
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ronald
Top achievements
Rank 1
Pedro
Top achievements
Rank 1
Philip
Top achievements
Rank 1
Ganesh Jagdale
Top achievements
Rank 1
Share this question
or