I'm new using MVC and Kendo.
I have this controller:
public ActionResult Index()
{
db.Configuration.ProxyCreationEnabled = false;
return View(db.students.ToList());
}
The View has this:
@model IEnumerable<MVC_Test1.Models.student>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Pageable(pager => pager
.PageSizes(new[] { 2, 3, 4 })
.ButtonCount(5))
.Sortable()
.Selectable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(2)
.ServerOperation(false)
)
.Columns(columns =>
{
columns.Bound(p => p.FirstName).Title("Name");
columns.Bound(p => p.MiddleName).Title("Middle");
columns.Bound(p => p.LastName).Title("Lastname");
columns.Bound(p => p.EnrollmentDate).Format("{0:" + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + "}").Title("Created");
columns.Command(commands =>
{
commands.Custom("Options");
}).Title("Options").Width(200);
})
- First I need to order the list by a property named "OrderPos" the Model students has.
- I'd like to drag and drop the rows to change the order and automatically update the database. So when I drag and drop a row it chages the field "OrderPos" in the database.
I have see the kendo sortable widget, but I don't know how to mix everything to have this working. Here is the demo: http://demos.telerik.com/kendo-ui/sortable/integration-grid
Thank you.
drop
is completed, inside that event you can fire an Ajax call and send the grid's data with it. So your controller will have the GridView bound to a list of YourModel class, and they should be ordered based on how they look in the view. That's gonna be the hardest part. I'll let you figure out how to update the database from there :) There's plenty of examples on posting Kendo Grids data. If your really struggling I'll show you how to post it. – CSharper