Update to add UI Element to remove sorting

Jul 31, 2015 at 9:42 PM
Edited Aug 11, 2015 at 7:19 PM
One of my pet peeves with GridMVC is the inability to remove the sort - I added some simple code to SortColumnHeaderRenderer.cs at line 49

From this:
            var sortArrow = new TagBuilder("span");
            sortTitle.InnerHtml += sortArrow.ToString();
to this:
            //get our URL w/o sorting
            string url = GetRemoveSortUrl(column.Name);
            //create our A tag
            var sortArrorLink = new TagBuilder("a");
            string urlRemove = GetRemoveSortUrl(column.Name);
            sortArrorLink.Attributes.Add("href", urlRemove);
            sortArrorLink.Attributes.Add("style", "text-decoration: none;");
            //create our span tag
            var sortArrow = new TagBuilder("span");
            //add span to A
            sortArrorLink.InnerHtml += sortArrow.ToString();
            //Add A and Span
            sortTitle.InnerHtml += sortArrorLink.ToString();

With a helper function:
    private string GetRemoveSortUrl(string columnName)
        //determine current url:
        var builder = new CustomQueryStringBuilder(_settings.Context.Request.QueryString);
        string url = builder.GetQueryStringExcept(new[]
        if (string.IsNullOrEmpty(url)) {
            url = "?";
        return url;
Now you just click on the arrow to remove the sort - not very intuitive, but it works.