[英]Sorting on Kendo UI MVC Grid
I am developing with Kendo UI Grid with MVC 5. I am finding that I cannot appear to get the sorting working on my columns - I have read the Thread here - http://www.telerik.com/forums/grid-sorting-filtering---doesn-t-work but looking at my Bundle configs it looks like I have the correct js files included and looking at the Network in F12 as well it looks like they have been included. 我正在使用带有MVC 5的Kendo UI Grid开发。我发现我似乎无法对列进行排序-我在这里阅读了线程-http: //www.telerik.com/forums/grid-sorting-过滤---不工作,但查看我的Bundle配置,看起来好像我包含了正确的js文件,然后看着F12中的Network也看起来好像已经包含了它们。 I am using Bootstrap as well in my site - is there possibly something else needed to be included? 我也在我的网站上使用Bootstrap-可能还需要包含其他内容吗?
Bundle configs are as below: 捆绑包配置如下:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery.validate.js",
"~/Scripts/jquery.validate.unobtrusive.js"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new ScriptBundle("~/bundles/kendo").Include(
"~/Scripts/kendo/kendo.all.min.js",
"~/Scripts/kendo/kendo.aspnetmvc.min.js"));
In my _Layout.cshtml I have the following in the section 在我的_Layout.cshtml中,本节中包含以下内容
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/kendo/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/kendo")
After @RenderBody() in _Layout.cshtml I have the includes for bootstrap 在_Layout.cshtml中的@RenderBody()之后,我包含了引导程序的包含内容
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/initialize")
@RenderSection("scripts", required: false)
The folllowing shows the config of my Grid 以下显示了我的网格的配置
@(Html.Kendo().Grid<Car.Web.Models.CarViewModel>()
.Name("CarView")
.Columns(columns =>
{
columns.Bound(c => c.Name).Width(180);
columns.Bound(c => c.ModelNo).Width(280);
columns.Bound(c => c.Colour).Width(120);
columns.Bound(c => c.FuelType).Width(65);
})
.HtmlAttributes(new { style = "height: 420px;" })
.Scrollable()
.Sortable(sortable => sortable
.AllowUnsort(true)
.SortMode(GridSortMode.MultipleColumn))
.Pageable(pageable => pageable
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetCarById", "api/Car"))
)
)
Note I am using WebAPI controller - the CarController in my API folder looks like below: 注意我正在使用WebAPI控制器-我的API文件夹中的CarController如下所示:
public DataSourceResult Read([DataSourceRequest] DataSourceRequest request)
{
//note stubbed data 1 will need to be passed in as id
return GetCarById(1).ToDataSourceResult(request);
}
public IEnumerable<CarViewModel> GetCarById(int carId)
{
// call to service layer to get data
var carResponse = _carService.GetCarDataById(carId);
// map responses to grid
return MapCarSelectView(carResponse );
}
private static IEnumerable<CarViewModel> MapCarSelectView(IEnumerable<CarResponse> carResponses)
{
return carResponses.Select(carResponse => new CarViewModel
{
Id = carResponse.Id, CarName = carResponse.Name, CarModelNo = carResponse.ModelNo, Colour = carResponse .Colour, FuelType= carResponse.FuelType
}).ToList();
}
The data is getting returned to the table correctly but neither the Numeric column of ModelNo nor the Alphabetic columns of name/colour/fuel type are not getting sorted when I click the column header? 数据正确返回到表中,但是当我单击列标题时,ModelNo的Numeric列和名称/颜色/燃料类型的字母列都没有得到排序吗? Is there something missing in my configurtaion? 我的配置中缺少什么吗?
You are using WebAPI - this means you will have to write a custom model binder. 您正在使用WebAPI-这意味着您将必须编写自定义模型绑定程序。 The facts on the WebAPI case are covered here . 有关WebAPI案例的事实在此处介绍 。 To see a demo you should check this code library . 要查看演示,您应该检查此代码库 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.