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

Batch Editing MVC

3 Answers 348 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Santiago
Top achievements
Rank 1
Santiago asked on 11 Jul 2012, 08:03 PM
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.

3 Answers, 1 is accepted

Sort by
0
Santiago
Top achievements
Rank 1
answered on 11 Jul 2012, 08:37 PM
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.
0
Ezequiel
Top achievements
Rank 2
answered on 09 Oct 2015, 11:43 AM

Is there a way of doing this as Santiago mentioned?

 

Thanks,

Ezequiel

0
Alexander Popov
Telerik team
answered on 14 Oct 2015, 08:54 AM
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!
 
Tags
General Discussions
Asked by
Santiago
Top achievements
Rank 1
Answers by
Santiago
Top achievements
Rank 1
Ezequiel
Top achievements
Rank 2
Alexander Popov
Telerik team
Share this question
or