Passing additional info when changing a cell

2 posts, 0 answers
  1. Michele
    Michele avatar
    426 posts
    Member since:
    Jun 2009

    Posted 30 Aug 2013 Link to this post

    Hello,
    I've got a grid, at the cell change I need to call a store procedure based on the cell changed.... since the grid sends the whole row, is there a way server side to understand which cell has fired the event?
    Thanks
    @(Html.Kendo()
        .Grid<DO.Admin.Utente>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(x => x.IDDipendente).Visible(false);
            columns.Bound(x => x.IDUtente);
            columns.Bound(x => x.Nominativo);
            columns.Bound(x => x.Societa);
            columns.Bound(x => x.Filiale);
            columns.Bound(x => x.Ruolo);
            columns.ForeignKey(x => x.IDProfilo, (System.Collections.IEnumerable)ViewData["ListaProfili"], "ID", "Descr").Title("Profilo");//.EditorTemplateName("StatoTemplate");
            columns.ForeignKey(x => x.IDFunzione, (System.Collections.IEnumerable)ViewData["ListaFunzioni"], "ID", "Descr").Title("Funzioni");//.EditorTemplateName("StatoTemplate");
            columns.ForeignKey(x => x.IDStato, (System.Collections.IEnumerable)ViewData["ListaStati"], "ID", "Descr").Title("Stato");//.EditorTemplateName("StatoTemplate");
            columns.Bound(x => x.AccessoEureka).ClientTemplate("<input class'k-checkbox' type='checkbox' name='cb#= IDDipendente#' #= AccessoEureka ? 'checked' : '' #  /> ");
     
        })
        .Selectable( selectable =>
            {
                selectable.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row);
            })
        .ToolBar(toolBar =>
        {
            toolBar.Save();
        })
        .Pageable()
        .Scrollable()
        .Resizable(resize => resize.Columns(true))
        .Sortable()
        .Filterable()
        .Editable(editable => editable.Mode(GridEditMode.InCell))
        .Events(events =>
            {
                events.Change("onRowChange");
                //events.Edit("testEdit");
                events.Save("testSave");
                //events.SaveChanges("testSaveChanges");
            })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .ServerOperation(false)
            .Model(model =>
            {
                model.Id(x => x.IDDipendente);
                model.Field(x => x.IDUtente).Editable(false);
                model.Field(x => x.Nominativo).Editable(false);
                model.Field(x => x.Societa).Editable(false);
                model.Field(x => x.Filiale).Editable(false);
                //model.Field(x => x.Ruolo);
                //model.Field(x => x.Profilo);
                //model.Field(x => x.Funzioni);
                //model.Field(x => x.Stato);
                //model.Field(x => x.AccessoEureka);
            })
            .Read(read => read.Action("GetListaUtenti", "GestioneUtenti"))
            .Update( "UpdateStato", "GestioneUtenti")
            .Events(events => events.Error("error_handler"))
        )
    )
    Controller
    public ActionResult UpdateStato([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<IDEA20.DO.Admin.Utente> utenti)
            {
                if (utenti != null && ModelState.IsValid)
                {
                    //foreach (var utente in utenti)
                    //{
                    //    //product.Category = GetCategory(product.CategoryID);
                    //    //SessionClientProductRepository.Update(product);                   
                    //}
                }
     
                return Json(utenti.ToDataSourceResult(request, ModelState));
    }
    Thanks
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 03 Sep 2013 Link to this post

    Hello Paolo,

    Out-of-the-box there is nothing you can use, however there are events which you can use to save that information and send it to the server on a later event (when save is clicked).

    Basically when the save event of the Grid you can see which cell was changed - e.container points to the TD element in the Grid that was used, also the e.values object will have a field named like the column name which value will be the updated value.

    Another event that will provide you with similar information is the change  event of the dataSource. You can check if e.action is itemchange and use e.field - to understand which field was modified and the e.items[0] you have reference to the whole dataItem with the updated values.

    Once you know which cell/field of the model was modified you can save them in a global variable which you can later use and send that information to the server (in a way that you prefer) like explained here:

    http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/faq#how-do-i-send-values-to-my-action-method-when-binding-the-grid?


    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top