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

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

4 Answers 2299 Views
Window
This is a migrated thread and some comments may be shown as answers.
Marc Plaxton-Harrison
Top achievements
Rank 1
Marc Plaxton-Harrison asked on 12 May 2016, 01:02 PM

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")))
                                              
                                                
                                               )

4 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 16 May 2016, 07:05 AM
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
0
Marc Plaxton-Harrison
Top achievements
Rank 1
answered on 17 May 2016, 11:20 AM

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

0
Marc Plaxton-Harrison
Top achievements
Rank 1
answered on 17 May 2016, 11:21 AM
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
0
Accepted
Danail Vasilev
Telerik team
answered on 19 May 2016, 11:00 AM
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
Tags
Window
Asked by
Marc Plaxton-Harrison
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Marc Plaxton-Harrison
Top achievements
Rank 1
Share this question
or