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

Add data attribute to Columns .HtmlAttributes

1 Answer 2817 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ruairi
Top achievements
Rank 1
Ruairi asked on 02 Oct 2014, 01:58 PM
I have a Kendo Grid as in code below - I have a View column which calls a javascript function.
I want to add an action url to a custom data attribute i.e. data-actionurl on the column. In the javascript function I will then get the data attribute and redirect to that page.
Is this possible?


@(Html.Kendo().Grid<Mallons.DomainFire.Models.Houses>()
    .Name("gridFcRevised")
    .Columns(columns =>
    {
            columns.Command(command => command.Custom("View").Click("viewRevisedHouse")).Width("85px").HtmlAttributes( new {@data-actionurl=Url.Action('AjaxAdd', 'HouseFee', new {Oid = '#=Oid#'})});    //Error here
            columns.Command(command => command.Custom("View").Click("viewRevisedHouse")).Width("85px"); // This works fine
      columns.Bound(p => p.Oid).Visible(false);
      columns.Bound(p => p.ApplicationDate).Format("{0:dd/MMM/yyyy}").Title("Application Date");
      columns.Bound(p => p.RevisedHouseReason).Title("Revised Reason");
    })
    .Pageable()
    .Sortable()
    .Scrollable(s=>s.Height("auto"))
    .Filterable()   
    .DataSource(dataSource => dataSource
        .Ajax()
        .Events(e => e.Error("handleAjaxError"))
        .PageSize(10)
        .Read(read => read.Action("RevisedHouses_GridRead", "House", new {originalHouseOid= Model.Entity.Oid }))
     )
)





1 Answer, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 06 Oct 2014, 09:23 AM
Hello Tyler,

Adding URLs or calling custom JavaScript functions is always done by defining ClientTemplate for that column. You can find example in our FAQ section from the docs:

http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/faq#how-do-i-use-action-links
http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/faq#how-do-i-use-a-javascript-function-in-a-column-client-template

Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Ruairi
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or