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

Need help with template column

4 Answers 793 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 2
James asked on 16 Oct 2012, 02:27 PM
HI all,

I'm a bit new to Kendo, so forgive me if this is an easy question;

I have a grid of orders. The last column of the grid needs to be a link/button/whatever that launches a bit of JavaScript that does some AJAX stuff. Pretty simple. I found that documentation on the columns.Template method and I _think_ that's what I want. The problem is that I have only found examples where one field from the model is being used in the method call and I need three;
columns.Template(p =>
{@<a href="#"
onclick="GetListOfVendorsByCountyAndProductType('@p.County', '@p.ProductTypeId.ToString()', '@p.OrderId');">Select Vendor</a>;       
                                          });
 I tried the snippet above but I got an error on the page that said "CS0201: Only assignment, call, increment, decrement, await and new object expressions can be used as a statement"

Any advice? Please remember I'm VERY new to the Kendo stuff.

Thanks,
James

4 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 19 Oct 2012, 10:15 AM
Hello James,

You can use the following syntax:

columns.Template(
    @<text>
        foo
        @item.ProductName
        @item.UnitPrice
        bar
    </text>
);

Note that is is a server template which works with server binding. If you are using Ajax binding, you need a ClientTemplate, as explained in the Grid configuration help article.

Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
James
Top achievements
Rank 2
answered on 19 Oct 2012, 03:12 PM
Thanks Dimo, that worked!
0
Hassan
Top achievements
Rank 1
answered on 09 Nov 2012, 06:17 PM
I get

CS0103: The name 'p' does not exist in the current context

when I try the proposed solution for AJAX binding. 

    @(Html.Kendo().Grid(Model)   
        .Name("products")
        .Columns(columns => {
            columns.Bound(p => p.Id).Visible(false);
            columns.Bound(p => p.Title).Width(280);
            columns.Bound(p => p.Brand).Width(70);           
            columns.Bound(p => p.SellPrice).Width(40);
            columns.Bound(p => p.PacketWeight).Width(60);
            columns.Bound(p => p.Enabled).Width(30);   
            columns.Template(@<text>
            @Html.ActionLink("Edit", "Home", new { id = p.Id })
       </text>);

        })
        .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id(p => p.Id))
        .Read(read => read.Action("GetProducts", "Product").Data("additionalData"))
        )
        .Pageable()
        .Sortable()
        .Navigatable()
        .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
    )

 

 

 

 

0
Rich Coleman
Top achievements
Rank 1
answered on 01 Feb 2013, 02:18 AM
Hassan,

It should be

 columns.Template(@<text>
            @Html.ActionLink("Edit", "Home", new { id = item.Id })
       </text>);
Tags
Grid
Asked by
James
Top achievements
Rank 2
Answers by
Dimo
Telerik team
James
Top achievements
Rank 2
Hassan
Top achievements
Rank 1
Rich Coleman
Top achievements
Rank 1
Share this question
or