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

How to pass variables in Grid Column ClientTemplate

1 Answer 3276 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 09 Jul 2013, 12:12 AM
Hello,

I would like to use ClientTemplate in a Grid column. I want to create html link in one of those column. I am not sure how declare and pass a variable of the Model that I am passing into the grid. I am trying to pass the variable ID and the name for the link as variable. model => model.IDString contains the id that is being passed to link and name of the link is represented in model => model.ViewImage.  

Here is the piece of code I am using.

<div id="SearchResultGrid">
        @(Html.Kendo().Grid(Model)
        .Name("ExampleGrid")
        .Columns(columns =>
        {
            columns.Bound(model => model.IDString).Title("ID");
            columns.Bound(model => model.ViewImage).Title("View Image").ClientTemplate(model =>(
                "<a href='/Example/ExampleDocument.aspx?Id=" + model.IDString + "' >" + model.ViewImage + "</a>")
                ); 
        })
     .Pageable()
     .Sortable()
     .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(10)
        .ServerOperation(false)
        .Sort(sort =>
        {
            sort.Add(model => model.Created).Descending();
        })
        )
 .BindTo(Model)
     .Reorderable(reorder => reorder.Columns(true))
 )
</div>  

Can you give me an example of how declare the variable for this action link.
Following line works well for a server action 

columns.Template(model =>(
                "<a href='/Provider/ProviderCorrespondenceDocument.aspx?CorrespondenceId=" + model.IDString + "' >" + model.ViewImage + "</a>")
                );
 

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Top achievements
Rank 1
answered on 09 Jul 2013, 02:58 AM
Hello,

I found the answer so please ignore my request.

Information for others:
To use a variable inside column ClientTemplate use Kendo Template  described at
http://docs.kendoui.com/getting-started/framework/templates/overview
and I found that information at
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/faq
look under heading "Example: Customize the Column Appearance of a Ajax Bound Grid"

My working piece of code is
columns.Bound(model => model.ViewImage).Title("View Image").ClientTemplate(
"<a href='/Example/ExampleDocument.aspx?Id= #= IDString # ' target=\"_blank\" > #= ViewImage # </a>"
);


Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Share this question
or