webgrid default sort direction

3.2k Views Asked by At

when i add the web grid to my page in mvc project it sortes the data ascending on first click. but i bring the data already sorted ascendin. then nothing happens. i want webgrid to sort descending at first.

you can see the code of my grid creation

var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5, 
selectionFieldName: "selectedRow",ajaxUpdateContainerId: "gridContent");
    grid.Pager(WebGridPagerModes.NextPrevious);

by the way i have tried the below code but it doesnt work.

if (Request.QueryString[grid.SortDirectionFieldName].IsEmpty())
{
    grid.SortDirection = SortDirection.Descending;
}
1

There are 1 best solutions below

0
Splendor On

Try adding a defaultSort property to your WebGrid instantiator:

var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5, selectionFieldName: "selectedRow",
           ajaxUpdateContainerId: "gridContent", defaultSort: "YourColumnName");