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

[Solved] OnCommand not firing

1 Answer 192 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.
Dan
Top achievements
Rank 1
Dan asked on 18 Nov 2011, 04:09 AM
I am using the latest release of the MVC grid.  I am trying to get the OnCommand client side event to work but it doesn't seem to be firing.  Here is a sample of my code (I am using VB):

<script type="text/javascript">
function Grid_onCommand(e) {
    alert("here");
    if (e.name == "cancelChanges") {
        alert("there");
        // pass additional data to the action method using e.data and e.dataItem
        e.data = $.extend(e.data, {
            Id: e.dataitem.ArticleId
        });
    }
}
 
function onLoad(e) { alert("Grid loaded"); }
</script>
 
@(Html.Telerik().Grid(Model) _
    .Name("ArticleCategoryGrid") _
    .ToolBar(Sub(commands) commands.Insert()) _
    .DataKeys(Sub(datakeys)
                      datakeys.Add(Function(dk) dk.ArticleCategoryId)
              End Sub) _
    .DataBinding(Sub(dataBinding)
                         dataBinding.Server.Select("Index", "ArticleCategory", New With {.id = ViewData("ArticleId")})
                         dataBinding.Server.Insert("Insert", "ArticleCategory")
                         dataBinding.Server.Update("Update", "ArticleCategory")
                         dataBinding.Server.Delete("Delete", "ArticleCategory")
                 End Sub) _
    .Columns(Sub(columns)
                     columns.Bound(Function(ac) ac.CategoryId)
                     columns.Bound(Function(ac) ac.StartDate)
                     columns.Bound(Function(ac) ac.EndDate)
                     columns.Bound(Function(ac) ac.ShowLink)
                     columns.Bound(Function(ac) ac.DateCreated).Visible(False)
                     columns.Bound(Function(ac) ac.DateUpdated).Visible(False)
                     columns.Command(Sub(commands)
                                             commands.Edit()
                                             commands.Delete()
                                     End Sub)
             End Sub) _
    .Sortable() _
    .Pageable(Sub(p)
                      p.PageSize(10, New Integer() {10, 25, 50})
                      p.Style(GridPagerStyles.NextPrevious Or GridPagerStyles.Numeric Or GridPagerStyles.PageSizeDropDown Or GridPagerStyles.PageInput)
              End Sub) _
    .Filterable() _
    .ClientEvents(Sub(events)
                          events.OnCommand("Grid_onCommand")
                          events.OnLoad("onLoad")
                  End Sub)
)

As you can see, I added an alert to the Grid_onCommand function just to see if it was reaching the code, and nothing happens.  I do get the alert for the onLoad function, so that event is firing correctly.

Can you tell me if there is something else that I need to do?

Thanks.

Dan

1 Answer, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 22 Nov 2011, 03:34 PM
Hi Dan,

 This behavior is expected - you are using server-side binding for the grid so only the OnLoad event will be called. The rest of the events are client-side ones and will work with client-side binding.



All the best,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Dan
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Share this question
or