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

Sometimes my grid will refire events

3 Answers 9 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Logan
Top achievements
Rank 1
Veteran
Logan asked on 13 Jan 2014, 08:29 PM
For instance, it might fire the create event on every CRUD event.  I cannot say it is always the case, but it appears to normally be re-firing an event that was already fired (and processed).

My grid is bound to a ModelView for the and we actual do the update on the database model, but i always fill in the key on the object that was passed in and then return the modelView. 

Below is an example of the grid in my view:
             @(
Html.Kendo().Grid<.Models.ConnectionView>()
       .Name("ConnectionView")
       .Columns(columns =>
           {
               columns.ForeignKey(c => c.ConnId, Model.All, "Value", "Text").Title("Restriction");
               columns.Bound(c => c.MaxEnrollment);
               columns.Command(command =>
                       {
                           command.Custom("move-up").Text("u").Click("OnMoveUp");//, "Home", new {Area="Sessions",id="#=Id#" });
                           command.Custom("move-down").Text("d").Click("OnMoveDown");//, "Home", new { Area = "Sessions", id = "#=Id#" });
                           command.Edit();
                           command.Destroy();
                       });
           })
           .Pageable(page =>
                   {
                       page.Enabled(true);
                       page.Input(false);
                       page.Numeric(false);
                       page.PreviousNext(true);
                       page.Messages(message => message.Empty("There are no records to show.  Click the Add button to create a row"));
                   })
           .ToolBar(toolbar => toolbar.Create().Text("Add"))
           .Editable(editable => editable.Mode(GridEditMode.InLine))
           .DataSource(dataSource => dataSource
           .Ajax()
           .Events(events =>
               {
                   events.Error("error_handler");
               })
           .Model(model =>
               {
                   model.Id(m => m.Id);
                   model.Field(m => m.ConnId).DefaultValue(int.Parse(Model.All.First().Value));
               })
           .Create(update => update.Action("ConnectionView_Create", "Home"))
           .Read(read => read.Action("ConnectionView_Read", "Home"))
           .Update(update => update.Action("ConnectionView_Update", "Home"))
           .Destroy(update => update.Action("ConnectionView_Destroy", "Home"))
           )
Example of my create method:
public ActionResult RestrictionConnectionView_Create([DataSourceRequest] DataSourceRequest request, RestrictionConnectionView connector)
{
    var newConn = new OrientationSession_RestrictionConnector();
    if (ModelState.IsValid)
    {
        var restrictionRepo = new EFRepository<Restriction>(_uow);
        var restriction = restrictionRepo.GetByKey(connector.RestrictionId);
        var repo = new EFRepository<Conn>(_uow);
        var session = repo.WhereIncluding(w => w.Id == _WorkingSessionId, i => i.RestrictionConnectors).FirstOrDefault();
 
        if (session != null && restriction != null)
        {
            newConn.OrientationSessionId = _WorkingSessionId;
            newConn.Restriction = restriction;
            newConn.MaxEnrollment = connector.MaxEnrollment;
            newConn.CreatedBy = User.Identity.Name;
            newConn.SequenceNumber = session.RestrictionConnectors == null || session.RestrictionConnectors.Count == 0 ? 1 : session.RestrictionConnectors.Max(m => m.SequenceNumber) + 1;
 
            session.RestrictionConnectors.Add(newConn);
            repo.Update(session);
            _uow.Commit();
            ResetSessionVars();
        }
    }
 
    connector.Id = newConn.Id;
 
    return Json(new[] { connector }.ToDataSourceResult(request, ModelState));
}

Thanks,
Logan

3 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 15 Jan 2014, 02:35 PM
Hi Logan,

I'm not sure that I understand correctly what is the exact issue that you are experiencing, however if when you try to update given record the "Create" Action is called instead of "Update" action most probably there is some issues with the Id's of the Grid records. If this is the case - please provide sample response returned from the server during the initial read in order to investigate further. Also if possible provide the "ConnectionView_Read" Action code. 


Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Logan
Top achievements
Rank 1
Veteran
answered on 16 Jan 2014, 01:34 PM
So basically what is happening is:

 1. i use inline editing to create a new record
        - The grid fire 1 create event
 2. I use inline editing to delete the newly created record
        -The grid fires the exact same create event from step 1
        -The grid will fire the delete event

In some situations the objects were stored in a session instead of being added into the database and this would cause the Id (the key field) to not be filled in on the object that was returned to the grid.  After filling in the Id  with a sentinel value (that is unique in the list) in the non-save situation seems to have fixed the problem.  
I was a little surprised that i didn't see this issue brought up before (at least i couldn't find it) so I wanted to just confirm that my "fix" is indeed a fix and there there are no other situations that would cause this kind of repost.

Thanks,
-Logan
0
Vladimir Iliev
Telerik team
answered on 17 Jan 2014, 01:17 PM
Hi Logan,

Current solution looks valid fore reading and creating records(will not cause more additional "create" requests), however you should make sure that the "update" and "delete" actions are working correctly as the Grid will now send that fake IDs to the server. A better solution would be to save the real IDs in the session.

Kind Regards,
Vladimir Iliev
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
Logan
Top achievements
Rank 1
Veteran
Answers by
Vladimir Iliev
Telerik team
Logan
Top achievements
Rank 1
Veteran
Share this question
or