mardi 5 mai 2015

Kendo UI Grid - Add new record

I am using kendo UI grid with inline Add/Edit. In that I have button which adds new row to the grid to add new record.

My problem is if I keep clicking on "Add New Record" button it will keep adding new row to the grid.

Below is my code for grid:

@{Html.Kendo().Grid<myclass>()                                    
                                .ToolBar(t => t.Create().Text("Add New Record"))
        .Name("MyGrid")
        .Filterable()
                                  .Events(e => e.Edit("onEdit"))
        .DataSource(dataSource => dataSource
                      .Ajax()
            .Events(e => e.Error("Error_handler").RequestEnd("onGridRequestEnd"))
                      .ServerOperation(false)
                      .Model(model => model.Id(p => p.id))
                      .Read(read => read.Action("_AjaxBinding", "MyController").Type(HttpVerbs.Post))
                      .Create(create => create.Action("_SaveAjaxEditing", "MyController").Type(HttpVerbs.Post))                          
                      )
    .Columns(columns =>
    {
        /*  Some columns */
    })

 .Editable(editable => editable.Mode(GridEditMode.InLine).CreateAt(GridInsertRowPosition.Top))
 .Pageable(pageable => pageable.Refresh(true).PageSizes(GlobalCode.recordPerPageList).ButtonCount(GlobalCode.PageSize).Input(true).Numeric(true))
                             .HtmlAttributes(new { @class = "dynamicWidth" })
            .Sortable(sorting => sorting.Enabled(true))
                             .Render();
                        }

So when I click on first time on "Add New Record" button it will add new row like below

enter image description here

Now I again click on "Add New Record" button it will add another row in the grid as shown below:

enter image description here

I do not want to add new row when there is already row available in the grid for new record.

Aucun commentaire:

Enregistrer un commentaire