WebGrid排序不适用于Orchard

时间:2013-12-20 14:33:35

标签: asp.net-mvc orchardcms

我已经在我的果园自定义模块中应用了Webgrid,并且分页工作正常但我在排序方面遇到了问题。 排序仅适用于一个设置为defaultSort的列,另一列排序不起作用。

<div id="gridList">
                @{
    var grid = new WebGrid<Models.ServicePart>(null, rowsPerPage: Model.PageSize, canPage: true, defaultSort: "Name", ajaxUpdateContainerId: "myGrid");
                    grid.Bind(Model.ServiceList, rowCount: Model.TotalCount, autoSortAndPage: false);
                    grid.Pager(mode: WebGridPagerModes.All);
                }
                <div id="myGrid">
                    @MvcHtmlString.Create(grid.GetHtml(tableStyle:"items", columns: grid.Columns(
                    grid.Column("Name",header: "Name",style:"width30percent"),
                    grid.Column(columnName:"Contact",header: "Contact", style:"width30percent"),
                    grid.Column("ServiceTypeRecord.TypeName",header: "Service Type",style:"width25percent"),
                    grid.Column("", header: "Action", format :(item) => Html.Raw(
                        (Authorizer.Authorize(Permissions.EditContent, item) ?  (Html.ItemEditLink(T("Edit").Text, item)).ToString() : "") + " | " + (Authorizer.Authorize(Permissions.EditContent, item) ?  (Html.Link(T("Delete").Text, Url.ItemRemoveUrl(item, new { returnUrl }), new { itemprop = "RemoveUrl UnsafeUrl" })).ToString() : "")
                      ),style:"width15percent")
                    )).ToString())
                </div>
            </div>

仅对Name列进行排序,因为它是默认排序。如果将列联系人设置为默认值,则只联系列排序工作。

1 个答案:

答案 0 :(得分:0)

将我的模型绑定到webgrid时所需的列名所以请在grid.Bind中添加列名。函数排序将起作用。

  var grid = new WebGrid<Models.ServicePart>(null, rowsPerPage: Model.PageSize, canPage: true, defaultSort: "Name", ajaxUpdateContainerId: "myGrid");
                grid.Bind(Model.ServiceList,new[]{"Name","Contact","ServiceTypeRecord.TypeName"}, rowCount: Model.TotalCount, autoSortAndPage: false);
                grid.Pager(mode: WebGridPagerModes.All);