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

Passing additional info when changing a cell

1 Answer 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 30 Aug 2013, 10:31 AM
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

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 03 Sep 2013, 05:41 AM
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!
Tags
Grid
Asked by
Michele
Top achievements
Rank 2
Answers by
Petur Subev
Telerik team
Share this question
or