Batch Editing MVC

4 posts, 0 answers
  1. Santiago
    Santiago avatar
    6 posts
    Member since:
    Jul 2012

    Posted 11 Jul 2012 Link to this post

    Hello everyone,

    I have some examples with Telerik MVC, one of them is a batch editing grid in MVC, works great but now i need to copy that example to Kendo MVC and the library is not the same (i have the latest version: kendoui.trial.2012.2.710)

    Altough i can't find examples of Kendo MVC Libraries in the API section, why?

    I can set the action of the save command  or the create ?

    I have the following code:

    @(Html.Kendo().Grid<PersonalDto>()
    .Name("Grid")
    .Columns(columns =>
                {
                    columns.Bound(p => p.PersonalID).Width(50);
                    columns.Bound(p => p.FirstName).Width(100);
                    columns.Bound(p => p.LastName).Width(100);
                    columns.Bound(p => p.DateBeginToWork).Width(120);
                })
                .DataSource(dataSource => dataSource
                    .Ajax() // Specify that the data source is of ajax type
                    .Model(model => model.Id(p => p.PersonalID))
                    .ServerOperation(false)
                    .Read(read => read.Action("FillGrid", "Personal").Data("fnGetSelectedProjectID") // Specify the action method and controller name
                    
                ))
                .Editable(editing => editing.Mode(GridEditMode.InCell))
                .ToolBar(commands =>
                {
                    commands.Create();
                    commands.Save();
                })
                .Pageable()
    )

    Thanks 
    Santiago.
  2. Santiago
    Santiago avatar
    6 posts
    Member since:
    Jul 2012

    Posted 11 Jul 2012 Link to this post

    I found this code in the http://demos.kendoui.com/web/grid/editing.html 

    In Demo source code, select source file: editing.cshtml

    @(
    Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()    
        .Name("Grid")    
        .Columns(columns => {        
            columns.Bound(p => p.ProductName);
            columns.Bound(p => p.UnitPrice).Width(140);
            columns.Bound(p => p.UnitsInStock).Width(140);
            columns.Bound(p => p.Discontinued).Width(100);
            columns.Command(command => command.Destroy()).Width(110);
        })
        .ToolBar(toolbar => {
            toolbar.Create();
            toolbar.Save();        
        })
        .Editable(editable => editable.Mode(GridEditMode.InCell))
        .Pageable()
        .Sortable()
        .Scrollable()
        .DataSource(dataSource => dataSource        
            .Ajax()         
            .Batch(true)
            .ServerOperation(false)
            .Events(events => events.Error("error_handler"))
            .Model(model => model.Id(p => p.ProductID))
            .Create("Editing_Create", "Grid")
            .Read("Editing_Read", "Grid")
            .Update("Editing_Update", "Grid")
            .Destroy("Editing_Destroy", "Grid")
        )
    )
    <script type="text/javascript">
        function error_handler(e) {    
            if (e.errors) {
                var message = "Errors:\n";
                $.each(e.errors, function (key, value) {
                    if ('errors' in value) {
                        $.each(value.errors, function() {
                            message += this + "\n";
                        });
                    }
                });        
                alert(message);
            }
        }
    </script>


    Another question, is any posibility to call 1 action with 3 lists and not one by one ? (create, update, destroy)


    Like this example: http://demos.telerik.com/aspnet-mvc/grid/editingbatch 

    public ActionResult _SaveBatchEditing([Bind(Prefix = "inserted")]IEnumerable<EditableProduct> insertedProducts,
               
    [Bind(Prefix = "updated")]IEnumerable<EditableProduct> updatedProducts,
               
    [Bind(Prefix = "deleted")]IEnumerable<EditableProduct> deletedProducts)
    {
       
    if (insertedProducts != null)
       
    {
           
    foreach (var product in insertedProducts)
           
    {
               
    // perform insert
           
    }
       
    }

       
    if (updatedProducts != null)
       
    {
           
    foreach (var product in updatedProducts)
           
    {
               
    //perform update
           
    }
       
    }

       
    if (deletedProducts != null)
       
    {
           
    foreach (var product in deletedProducts)
           
    {
               
    //perform update
           
    }
       
    }
       
       
    return View(new GridModel(SessionProductRepository.All()));
    }


    Thanks
    Santiago.
  3. Kendo UI is VS 2017 Ready
  4. Ezequiel
    Ezequiel avatar
    36 posts
    Member since:
    Oct 2011

    Posted 09 Oct 2015 Link to this post

    Is there a way of doing this as Santiago mentioned?

     

    Thanks,

    Ezequiel

  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 14 Oct 2015 Link to this post

    Hi Ezequiel,

    Making a single request that included all pending CRUD operations is not supported out of the box. This behavior however, could be achieved using a custom solution, as demonstrated here:
    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready