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

Column ClientTemplate issues

1 Answer 226 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 07 Dec 2012, 11:36 PM
I have a Hierarchy style Kendo grid and the inner grid doesn't seem to accept client templates. (I stripped the code irrelevant grid configuration columns out )  
I really would like the client template to be something like
        <a title="#=AlarmStatusDescription#">#=AlarmStatus#</a>`   but anytime I put anything other than a simple string in the ClientTemplate, the whole grid fails to load.        
   
I've tried 
ClientTemplate(#:AlarmStatus#)
.ClientTemplate(#=AlarmStatus#)
.ClientTemplate(<div class="myclass"></div>) with a separate <script type="text/html" id="myclass">#=AlarmStatus#</script>


   

  
@(Html.Kendo().Grid<AccountModel>()
                   .Name("Accounts_#=Id#")
                   .Columns(columns =>
                                {         
    columns.Command(command => command.Custom("Details").Click("showDetails")).Width(75);
    columns.Bound(o => o.AccountName).Width(150);                 
    columns.Bound(o => o.AlarmStatus).Width(100).ClientTemplate("#:AlarmStatus#");`
            
                                    })
                       .DataSource(dataSource => dataSource
                           .Ajax()
                           .Model(model =>{model.Id(p => p.AccountId);})
                           .Read(read => read.Action("DetailRead", "Csr", new { personId = #=Id#" }))
                       )
                       .Editable(editable => editable.Mode(GridEditMode.PopUp))
                       .ToClientTemplate()
               )


1 Answer, 1 is accepted

Sort by
0
Chad
Top achievements
Rank 1
answered on 08 Dec 2012, 06:31 PM
Here's one that I just did and it works. There is a call out to a js function that builds the html stings and returns it to the client template..hopefully this will help you:
columns.Bound(l => l.DisplayLocation).Width(150).ClientTemplate("#= getDetailsLink2(Id, DisplayLocation) #");
Here is the js function:
function getDetailsLink2(itemId, linkText) {
      
        var link = "<a href='" + '@Url.Action("Edit", "ManageLocations")'+"/" + itemId +"' class='k-link'>"
                    + linkText + "</a>";
        return link;
    }
Here is even a simpler js function you can use to test:
function getDetailsLink(id) {
        return "/CompanyMgmt/ManageLocations/Edit/" + id;
    }
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Chad
Top achievements
Rank 1
Share this question
or