简体   繁体   English

ASP.NET MVC和Kendo Grid Sortable

[英]ASP.NET MVC & Kendo Grid Sortable

I'm new using MVC and Kendo. 我是使用MVC和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. 首先,我需要通过模型学生具有的名为“ OrderPos”的属性对列表进行排序。
  • 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. 因此,当我拖放一行时,它将更改数据库中的“ OrderPos”字段。

I have see the kendo sortable widget, but I don't know how to mix everything to have this working. 我已经看到kendo可排序的小部件,但我不知道如何混合所有内容以使其正常工作。 Here is the demo: http://demos.telerik.com/kendo-ui/sortable/integration-grid 这是演示: http : //demos.telerik.com/kendo-ui/sortable/integration-grid

Thank you. 谢谢。

Have you looked at their example here: http://demos.telerik.com/aspnet-mvc/sortable/integration-grid ? 您是否在这里查看过他们的示例: http : //demos.telerik.com/aspnet-mvc/sortable/integration-grid

They have the grid + sortable working with the MVC helpers. 他们与MVC助手一起使用grid + sortable。

Post the Grid to the server on some event 在某些情况下将网格发布到服务器

var gridData = $("#ProposalGridX").data("kendoGrid");

            $.ajax({
                url: "/GridPost/PersonPost",
                type: 'POST',
                data: JSON.stringify(gridData.dataSource.view()),
                dataType: 'json',
                contentType: 'application/json',
                success: function (data) {

                }
            });


        [HttpPost]
        public JsonResult PersonPost(List<QPM.Models.PortfolioViewModel> model)
        {
            //model will contain gridview
            //update OrderPos
        }

You'll want to handle the change event of the Sortable widget, and do an ajax post in there to update values on the server-side. 您将要处理Sortable小部件的change事件,并在其中进行ajax发布以更新服务器端的值。

See the events demo for more info: http://demos.telerik.com/aspnet-mvc/sortable/events 有关更多信息,请参见事件演示: http : //demos.telerik.com/aspnet-mvc/sortable/events

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM