Kendo UI grid ClientTemplate

anilca picture anilca · May 2, 2013 · Viewed 23k times · Source

I'm binding client templates to columns in my kendo ui grid as you see below:

@(Html.Kendo().Grid(Model)
        .Name("marketWatchGrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.direction).ClientTemplate(
                    "# if (direction==1) {#" +
                        "▲" + 
                    "#}#" +
                    "# if (direction==0) {#" +
                        "▼" + 
                    "#}#"
                ).Title("").Width(30);
            columns.Bound(p => p.symbol).ClientTemplate("<a href='javascript:selectSymbol('" + "#: symbol #" +"')'>#: symbol #</a>"); ;
            columns.Bound(p => p.bid);
            columns.Bound(p => p.ask);
        })
        .Scrollable()
    )

The following template does not work:

columns.Bound(p => p.symbol).ClientTemplate("<a href='javascript:selectSymbol('" + "#: symbol #" +"')'>#: symbol #</a>"); ;

I'm getting Javascript syntax error. How can I fix this?

Answer

anilca picture anilca · May 2, 2013

I changed my template to:

columns.Bound(p => p.symbol).ClientTemplate("<a href=javascript:selectSymbol(\'" + "#: symbol #" +"\')>#: symbol #</a>");

It works fine now.