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

Fire action from custom command column in Client details template

2 Answers 488 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shannon
Top achievements
Rank 1
Shannon asked on 30 Nov 2012, 07:30 PM
I have a custom command button in a Client template that I want to fire a specific action.  I only want to fire the action. I do not want to redirect/render another View.  This is being done inside of a grid hierarchy.  Also, the action needs access to my model. Code for the template is below

<script id="myTemplate" type="text/kendo-tmpl">
<%: Html.Kendo().Grid<MyModel>()
     .Name("ThisGrid")
     .Columns(columns =>
     {
        columns.Bound(n => n.value)
                      .Title("Col1")
                      .Width(100);
        columns.Bound(n => n.IsEnabled)
                      .Width(100)
                      .ClientTemplate(
                          "# if (IsEnabled) { #" +
                               "Yes" + "#} else {#" +
                               "No" + "#}#");
        columns.Command(command => command.Custom(
                 "# if(IsEnabled) { #" +
                      "Disable" +
                      "#} else { #" +
                      "Enable" +
                      "#}#").Click("updateModel")).Width(40);
     })
     .DataSource(dataSource => dataSource
              .Ajax()
              .Read(read => read.Action(
                       "Binding_Model", "MyController")))
             .Pageable()
             .Sortable()
             .ToClientTemplate()
%>

2 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Iliev
Telerik team
answered on 04 Dec 2012, 05:06 PM
Hi Shannon,


Basically you should use the jQuery Post method inside the "updateModel" click handler to send the current row dataItem to the action:

function updateModel(element) {
    var currentRow = $(element.srcElement).closest("tr");
    var currentdataItem = $("#Grid").data().kendoGrid.dataItem(currentRow);
    $.ajax({
        type: 'POST',
        url: 'home/create',
        data: currentdataItem.toJSON()
    });
}
Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Shannon
Top achievements
Rank 1
answered on 04 Dec 2012, 05:38 PM
Thanks, Vladimir!
Tags
Grid
Asked by
Shannon
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Shannon
Top achievements
Rank 1
Share this question
or