How to change the default sort order to descending?

How can I change defaultSortmine webGridto the opposite / decreasing order? If it were SQL, I would add DESCsomewhere. Here is my working line of code for upstream sorting:

var grid = new WebGrid(dq, rowsPerPage: 50, defaultSort: "UWDate", ajaxUpdateContainerId: "grid" );

It sorts correctly by column UWDatein ascending order, but I would like it to sort the opposite / decreasing order.

+3
source share
4 answers

Another option is after grid initialization:

    grid.SortDirection = SortDirection.Descending;
+6
source

You can change the sort order in the initializer WebGridby placing spaceand then DESCin the parameter string defaultSort.

var grid = new WebGrid(Model, defaultSort: "UWDate DESC" ... );

: http://forums.asp.net/post/4962796.aspx

+1

framework, .

WebGrid grid = new WebGrid(Model.OrderByDescending(o=>o.Id),canPage: true);

This is the design representation syntax for printing a mesh model.

@grid.Gethtml()
Run codeHide result

This will print the webgrid in descending order directly in the MVC page view.

+1
source
@{

    WebGrid grid = new WebGrid(Model, null, null, 10, true, true, ajaxUpdateContainerId: "container-grid2");
}
-1
source

Source: https://habr.com/ru/post/1789614/


All Articles