In my asp.net MVC 4 application, I have a View with two Kendo UI Grids. One of them contains a list of Products with their attributes. I want the other one to have the exact same columns, but empty.
When I select a row on the first Grid, I want it to be removed from the first one and added to the second one. I also want to be able to remove rows from the second one and add them back to the first one. I don't know how to accomplish that. Here is there is an answer to my question, but I want to be able to implement this using Kendo UI asp.net MVC wrappers:
Kendo UI copying data through controls
I have a ViewModel like this:
public class SelectProductsViewModel
{
public IEnumerable<Product> Products { get; set; }
public IEnumerable<Product> SelectedProducts { get; set; }
}
My Controller Action looks like this:
public ActionResult SelectProducts()
{
var viewModel = new SelectProductViewModel
{
Products = GetProducts(), // Get Products form the database
SelectedProducts = new List<Product>()
}
return View(viewModel);
}
And, here is what I have in my View:
@(Html.Kendo().Grid(Model.Products)
.Name("productsgrid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName);
columns.Bound(p => p.Color);
columns.Bound(p => p.Size);
columns.Bound(p => p.Price);
})
.Pageable()
.Sortable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetProducts", "Product"))
.Model(model =>
{
model.Id("ProductID");
})
)
)
@(Html.Kendo().Grid(Model.SelecteProducts)
.Name("selectedproductsgrid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName);
columns.Bound(p => p.Color);
columns.Bound(p => p.Size);
columns.Bound(p => p.Price);
})
.Pageable()
.Sortable()
.Filterable()
.DataSource(dataSource => new DataSource())
)