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

[Solved] Using ClientTemplate with business logic

0 Answers 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sam
Top achievements
Rank 1
Sam asked on 02 Aug 2012, 12:01 AM
Good morning everyone,

i am running into an issue with the latest licensed "Telerik Extensions for ASP.NET MVC3" grid.  my current code is as follows:

@{Html.Telerik().Grid(Model)
    .Name("BlahBlah")
    .DataKeys(keys => keys.Add(k =>
        k.Id)
    )
    .Columns(columns =>
    {
        columns.Bound(o => o.Code)
            .Width(50);
        columns.Bound(o => o.Name)
            .Width(150);
 
        columns.Template
        (
            @<text>
                <a class="t-button t-grid-edit t-button-icon" href="#">
                    <span class="t-icon t-edit"></span>
                </a>
 
                @if (@item.Groups == null ||
                    @item.Groups.Count <= 0)
                {
                    <a class="t-button t-grid-delete t-button-icon" href="#" onclick="return false;">
                        <span class="t-icon t-delete"></span>
                    </a>
                }
                else
                {
                    <a disabled="disabled" class="t-button t-grid-delete t-button-icon" href="#" onclick="return false;">
                        <span class="t-icon t-delete-disabled" disabled="disabled"></span>
                    </a>
                }
            </text>
        )
            .Width(40)
            .HtmlAttributes(new { style = "text-align:center" });
    })
    .DataBinding(dataBinding =>
    {
        // The action method will return JSON
        dataBinding.Ajax().Select("WhoDat_AjaxBinding", "DataGroup");
    })
 
    .Pageable(paging =>
        paging.PageSize(15)
    )
    .Sortable()
    .Filterable()
    .Render();
}

now this works , it renders and i see my grid but this is not exactly what i am looking for.  Instead of using "columns.Template(...)", i need to use "columns.Bound(o => o.Id).ClientTemplate("...")"


i tried to do the following but does not seem to work.  I am not sure what i am doing incorrectly:

@{Html.Telerik().Grid(Model)
    .Name("BlahBlah")
    .DataKeys(keys => keys.Add(k =>
        k.Id)
    )
    .Columns(columns =>
    {
        string buttons = "<a class='t-button t-grid-edit t-button-icon' href='#'>" +
                            "<span class='t-icon t-edit'></span>" +
                        "</a>";
         
        if (@item.Groups == null ||
            @item.Groups.Count <= 0)
        {
            buttons += "<a class='t-button t-grid-delete t-button-icon' href='#' onclick='return false;'>" +
                                "<span class='t-icon t-delete'></span>" +
                            "</a>";
        }
        else
        {
            buttons += "<a disabled='disabled' class='t-button t-grid-delete t-button-icon' href='#' onclick='return false;'>" +
                                "<span class='t-icon t-delete-disabled' disabled='disabled'></span>" +
                            "</a>";
        }
 
        columns.Bound(o => o.Code)
            .Width(50);
        columns.Bound(o => o.Name)
            .Width(150);
 
        columns.Bound(o => o.Id)
            .ClientTemplate(@buttons)
            .Width(40)
            .HtmlAttributes(new { style = "text-align:center" });
 
    })
    .DataBinding(dataBinding =>
    {
        // The action method will return JSON
        dataBinding.Ajax().Select("WhoDat_AjaxBinding", "DataGroup");
    })
 
    .Pageable(paging =>
        paging.PageSize(15)
    )
    .Sortable()
    .Filterable()
    .Render();
}


I tried to look at my syntax but not sure what is the correct syntax that should be coded there.  Any help on this matter is very much appreciated.

Thank you so very much.

Have a nice day
Tags
Grid
Asked by
Sam
Top achievements
Rank 1
Share this question
or