Grid custom command does not find javascript function

2 posts, 0 answers
  1. Derek
    Derek avatar
    8 posts
    Member since:
    Mar 2019

    Posted 25 Jun 2019 Link to this post

    Hi

    I have based the following code on Grid / Custom command
    https://demos.telerik.com/aspnet-mvc/grid/custom-command


    @(Html.Kendo().Grid<MyProject.Models.Profiles>().
        Name("MyTable").
        Columns(columns =>
        {
            columns.Command(command => {
                command.Custom("Edit Details").Click("EditDetails");
            }).Width(120);
        })
        .HtmlAttributes(new { style = "height: 600px" })
        .BindTo(Model)
        .Scrollable()
        .Groupable()
        .Sortable()
        .Filterable()
    )
     
    <script>
        function EditDetails(e) {
            e.preventDefault();
        }
    </script>

    When I run the code I get the following error in the Developer Console(Edge & Chrome)
    Uncaught ReferenceError: EditDetails is not defined

    I have been unable to find the problem, any suggestions?

    Is there a way that i can call a controller method without going through javascript?

     

    Thanks

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5704 posts

    Posted 26 Jun 2019 Link to this post

    Hi Derek,

    Try moving the function declaration above the grid.

    On redirecting to an action - I an think of two easy ways:

    • use JS and call window.location.href = "mycontorller/myaction/someparam" where the event arguments of the custom command handler can be used to get the current row data item and use its fields in constructing the url
    • use the ClientTemplate of a column and place an anchor there that will point to the desired url - in a similar fashion, build its parameters with the data that comes from the model

     


    Regards,
    Marin Bratanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top