开发者

MVC 3 WebGrid Column Sort alphabatically, not according to table structure

I have assigned data to the webgrid but it sorting the columns alphabetically. it is not showing columns as like in asp datagrid according to table structure.

fo开发者_运维技巧r example if table have columns as"

id  title  artid   

then grid showing them after sorting the columns as:

artid  id title


If you are still looking for this answer I have found it here:

 <h2>Index</h2>
@{
    var grid = new WebGrid(source: Model,
        defaultSort: "id",
        rowsPerPage:10);    
}
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<div id="grid">
    @grid.GetHtml(columns: grid.Columns(
                    grid.Column("id", "ID"),
                    grid.Column("title", "Title"),
                    grid.Column("artist", "Artist")));
</div>

Hope this helps!


In addition to stuartmclark's post above, if you want to sort by descending, you can set the sort direction after your grid initialization.

grid.SortDirection = SortDirection.Descending;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜