Why is my grid calling create for every row of data?

3 posts, 0 answers
  1. Marc
    Marc avatar
    128 posts
    Member since:
    Jul 2010

    Posted 17 Feb 2016 Link to this post

    Why is my grid calling "CreateFooBar" for every row of data when delete and update are submitted? It's probably something stupid but I can't see it.

     

       @(Html.Kendo()
              .Grid<FooBarViewModel>()
              .Name("FooBarGrid")
              .Sortable()
              .Scrollable()
              .Filterable()
              .Resizable(g => g.Columns(true))
              .Columns(columns =>
              {
                  columns.Command(command =>
                  {
                      command.Edit();
                      command.Destroy();
                  }).Width(150);
                  columns.Bound(g => g.Id).Hidden();
                  columns.Bound(g => g.Name).Title("Name").Width(200);
                  columns.Bound(g => g.FooBarNumber).Title("FooBar<br />Number").Width(200);
                  columns.Bound(g => g.CreatedBy).Width(100).Title("Created By");
                  columns.Bound(g => g.CreatedDate).Width(100).Title("Created Dt");
                  columns.Bound(g => g.ModifiedBy).Title("Modified By").Width(100);
                  columns.Bound(g => g.ModifiedDate).Width(100).Title("Modified Dt");
              })
              .DataSource(dataSource => dataSource.Ajax()
                  .Model(model =>
                  {
                      model.Id(m => m.Id);
                      model.Field(p => p.CreatedBy).Editable(false);
                      model.Field(p => p.CreatedDate).Editable(false);
                      model.Field(p => p.ModifiedDate).Editable(false);
                      model.Field(p => p.ModifiedBy).Editable(false);
                  })
                  .Batch(false)
                  .PageSize(25)
                  .ServerOperation(false)
                  .Read(read => read.Action("GetFooBars", "FooBar"))
                  .Create(update => update.Action("CreateFooBar", "FooBar"))
                  .Update(update => update.Action("UpdateFooBar", "FooBar"))
                  .Destroy(update => update.Action("DeleteFooBar", "FooBar"))
                  .Events(ev => ev.RequestEnd("onSave"))
                  .Events(events => { events.Error("onError"); })
              )
              .ClientDetailTemplateId("collectionTemplate")
              .Events(ev => ev.Edit("onEdit"))
              .ToolBar(toolbar =>
              {
                      toolbar.Create().Text("Add FooBar");   
              })
              
              .Editable(editable => editable.Mode(GridEditMode.InLine))
                      .Pageable(pager => pager
                            .Input(true)
                            .Numeric(true)
                            .Info(true)
                            .PreviousNext(true)
                            .Refresh(true)
                            .PageSizes(new int[5] { 25, 50, 100, 200, 500 })
                        )
                        .ColumnMenu()
        )

  2. Marc
    Marc avatar
    128 posts
    Member since:
    Jul 2010

    Posted 17 Feb 2016 Link to this post

    For posterity is was because the Model Id was not getting set, so I guess the grid sees every line as new. Did this used to throw a javascript error?
  3. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2895 posts

    Posted 19 Feb 2016 Link to this post

    Hi Marc,

    Your observation is correct, the issue will occur when the ID is not assigned because in this case the error is considered as new. A missing ID never resulted in JavaScript errors, there is no reason to obligate the developer to assign IDs, in some cases, for example when the Grid is not editable, the ID is not mandatory.

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