How to get the selected row grid id after clicking edit button and pass the id to the action method?

5 posts, 1 answers
  1. Marc Plaxton-Harrison
    Marc Plaxton-Harrison avatar
    38 posts
    Member since:
    Mar 2008

    Posted 12 May Link to this post

    Hi guys, currently i have this scenario where i want to get the selected row id after clicking on the edit button and pass that id to the action method...

    Please let me know if this is possible. here is my code below that i have gathered so far...

    function disableOnEdit(e) {
                          var model = e.model; //gets the model of the currently edited row
                          var Department = model.DepartmentID; //gets the value of the field "Department"
                       
                  
                          $.ajax({
                              type: "POST",
                              data: Department,
                              url: '@Url.Action("GetUsers","Home")',
                              success: function (result) {
                                  console.log(result);
                              }
                                })
                     
                         
     
                          $(".k-edit-form-container").parent().width(520).height(500).data("kendoWindow").center();
     
                          
                      }

    and my grid code below
     
    <div  style="clear:both;  position:relative; padding-top: 10px">
    @(Html.Kendo().Grid<KendoUIApp1_Test.Models.IncidentsViewModel>()
                  .Name("grid")
                  .Columns(colums =>
        {
             */
            colums.Bound(p => p.DepartmentID).Hidden(true);
            colums.Bound(p => p.IncidentID).ClientTemplate("<a class='k-button' href='" + Url.Action("GetPDF", "Home") + "?IncidentID=#= IncidentID #'" + "> <span span class='k-icon k-i-pdf''></span>Get Incident Pdf</a>").Title("Download PDF").Filterable(false);
            colums.Bound(p => p.StatusName).Title("Status").Filterable(false);
            colums.Bound(p => p.ReferenceNo).Title("ReferenceNo").Filterable(false);
            colums.Bound(p => p.IncidentDate).Title("IncidentDate").ClientTemplate("#= kendo.format('{0:MM/dd/yyyy HH:mm:ss}',kendo.parseDate(IncidentDate)) #").Filterable(model => model.UI("IncidentDateFilter"));
            colums.Bound(p => p.AccountName).Title("AccountName").Filterable(false);
            colums.Bound(p => p.Department1).Title("Department").Filterable(false);
            colums.Bound(p => p.Description).Title("Description").Filterable(false);
            colums.Bound(p => p.Comments).Title("Comments").Filterable(false);
            colums.Bound(p => p.FirstName).Title("CurrentAssignedUser").Filterable(false);
            colums.Command(cmd => cmd.Edit());
     
        })
          .Filterable(filterable => filterable
            .Extra(true)
            .Operators(operators => operators
                .ForString(str => str.Clear()
                    .StartsWith("Starts with")
                    .IsEqualTo("Is equal to")
                    .IsNotEqualTo("Is not equal to")
     
                ))
            )
     
        .HtmlAttributes(new { style = "height:550px;" })
        .DataSource(datasource => datasource
        .Ajax() //Configure the grid data source
        .Events(Eevents => Eevents.RequestEnd("OnChangeRefresh"))
        .Model(model =>
            {
                model.Id(m => m.IncidentID);
     
     
            })
        .Read(read =>
        {
            read.Action("GetIncidents", "Home").Data("IncidentsFilter");
        })// set the action method which will return the data in json format
     
        .Update(update => update.Action("Incidents_Update", "Home"))
        )
     
        .Navigatable()
        .Groupable()
        .Pageable()
        .Reorderable(reorder => reorder.Columns(true))
        .Sortable()
        .Scrollable()
            .Events(events =>
                {
                    events.Save("onIncidentUserAssign");
                    // events.Save("onStatusChange");
     
                })
     
                .Events(eEvents => eEvents.Edit("disableOnEdit"))
     
            //.Events(events =>
            //{
            //  events.Save("onStatusChange");
            //   // events.Save("onStatusChange");
     
            //})
     
     
        .Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("Incidents")
                                                   .Window(w => w.Title("Edit Incident Details")
                                                   .HtmlAttributes(new {@class= "kendo-popup-editor" })
                                                   .Scrollable(false)
                                                   .Name("editWindow")))
                                                  
                                                    
                                                   )

  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1492 posts

    Posted 16 May Link to this post

    Hi Marc,

    To get the row index when the edit button is clicked you can refer to this forum post - http://stackoverflow.com/a/31619887

    To send parameters to the server you can pass a JavaScript function that will return the parameter to the Data() method - http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/faq#how-to-send-values-to-my-action-method-when-binding-the-grid. This relates not only to the read but the update operation as well.

    Regards,
    Danail Vasilev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Marc Plaxton-Harrison
    Marc Plaxton-Harrison avatar
    38 posts
    Member since:
    Mar 2008

    Posted 17 May Link to this post

    Hi Danail, Thanks for the reply, i actually managed to solve it by using this code below...

       function disableOnEdit(e) {
                            
     
                            var model = e.model; //gets the model of the currently edited row
                         
                                $.ajax({
                                    type: "POST",
                                    data: { DepartmentID: JSON.parse(model.DepartmentID) }, //gets the value of the field "Department"
                                    url: '@Url.Action("GetUsers","Home")',
                                    success: function (result) {
                                        console.log(result);
                                       // var DepartmentID = JSON.parse(model.DepartmentID);
                                        //arg.model.set("field name as string", "value as appropriate data type");
                                        //alert("success:" + DepartmentID);
                                    }
                                })
     
    But for some reason i cant load the data when the popup loads. Im passing the select id from the grid to the dropdownlist which i have on the popup when it loads in custom edit form

  5. Marc Plaxton-Harrison
    Marc Plaxton-Harrison avatar
    38 posts
    Member since:
    Mar 2008

    Posted 17 May in reply to Marc Plaxton-Harrison Link to this post

    But for some reason i cant load the data when the popup loads. Im passing the select id from the grid to the dropdownlist which i have on the popup when it loads in custom edit form
  6. Answer
    Danail Vasilev
    Admin
    Danail Vasilev avatar
    1492 posts

    Posted 19 May Link to this post

    Hello Marc ,

    You can examine the following forum post that treats similar issue - http://stackoverflow.com/questions/30895085/kendo-charts-ajax-request-not-reaching-the-action-method?answertab=active#tab-top

    You may also find useful this thread where is shown a possible approach for passing the grid row index to the dropdown editor template - http://www.telerik.com/forums/pass-grid-view-model-data-to-editor-template#KK2Gwd4RTUCX14752V6Oyg

    If the above resources, however, do not help it would be better to send me a fully runnable sample where the issue is reproducible, so that I can investigate it further.

    Regards,
    Danail Vasilev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready