2

我正在使用 WebGrid 来显示我的数据库中的数据表。该表有一列包含数量。我希望有人能告诉我为什么这个网格没有排序?

@{  
    WebGrid grid = new WebGrid(
        source: Model,
        rowsPerPage: 10,
        canPage: true,
        canSort: false,
        ajaxUpdateContainerId: "grid",
        ajaxUpdateCallback: "initGrid",
        sortFieldName: "Qty_containers",
        sortDirectionFieldName: "ASC"
    );
}

    <div id="grid" class="ajax">
            @grid.GetHtml(
                tableStyle: "border", headerStyle: "red",
                columns: grid.Columns(
                grid.Column(columnName: "Haulier", 
header: ResourceContext.Get("Model.ShortTerm.Haulier")),
                grid.Column(columnName: "ETA_vessel", 
header: ResourceContext.Get("Model.ShortTerm.ETA_vessel"), format:
                    @<text>
                        @item.ETA_vessel.ToShortDateString()
                    </text>),
                grid.Column(columnName: "Container_length", header: ResourceContext.Get("Model.ShortTerm.Container_length"), format:
                    @<text>
                            @{string length = item.Container_length.ToString();
                              if(length.Equals("_blank_")){
                                length = "";
                              }
                              else if(length.Equals("_x0032_0_ft")){
                                length = "20 ft"; 
                              }
                              else{
                                length = "30 ft";
                              }
                             }
                            @length
                    </text>),
                grid.Column(columnName: "Qty_containers", header: ResourceContext.Get("Model.ShortTerm.Qty_containers"), canSort: true)
                )
            ) 
        </div>

我的网格

4

2 回答 2

0

更改此属性,它应该可以工作canSort: true。在您的代码中“canSort”设置为“False”

于 2013-06-21T06:34:39.927 回答
0

我也遇到了“WebGrid”的问题。在你的收藏中试试这个:

objectModel.OrderByDescending(d => d.Qty_containers);
于 2012-10-02T22:37:18.390 回答