c# - WebGrid column header initial sort direction -


i've got webgrid shows report of amounts , customer wants when user clicks on headers initial sort direction should descending, how can achieve this?

i've found solution: since grid has got arrow symbol on clicked header displays sort direction, in callback function renders grid's partial view collect jquery header links haven't got sort symbol in text , replace "sortdir=asc" "sortdir=desc" in links' querystring, keeping eventual clicked sort column sort state , letting other ones start sorting descendingly, this:

var $sortinglikns = $grid.find("thead a[data-swhglnk=true]"); $sortinglikns.each(function (idx, elem) {     if ($(elem).text().indexof("▴") === -1 || $(elem).text().indexof("▾") === -1) {         $(elem).attr("href", $(elem).attr("href").replace("sortdir=asc", "sortdir=desc"));     } }); 

Comments