Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7159071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:10:11+00:00 2026-05-28T13:10:11+00:00

I am creating a WebGrid and am trying to enable sorting. Actually, sorting works

  • 0

I am creating a WebGrid and am trying to enable sorting. Actually, sorting works but I notice that you can only sort on columns where the columnName is not blank in the grid.columns call. So in my example I have this:

@grid.GetHtml(
    columns: grid.Columns(
        grid.Column(columnName: "", header: "Item title", format: @<text> @GetItemTitle(@item.InventoryReference) </text>),
        grid.Column(columnName: "OwnerReference", header: "Owner reference")
     )
);

In this exampple, Item title is not sortable but Owner reference is. The quesiton is, how do I get Item title to be sortable and why does this happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:10:12+00:00Added an answer on May 28, 2026 at 1:10 pm

    For columns where you have used custom format you will have to do the sorting yourself. So you will have to give your custom column a name which will be used for identifying it on the server:

    grid.Column(
        columnName: "title", 
        header: "Item title", 
        format: @<text> @GetItemTitle(@item.InventoryReference) </text>
    ),
    

    and the header of this column is clicked a query will be sent to the controller action that will look like this:

    /controller/action/?sort=title&sortdir=ASC
    

    So inside your controller action you will use this information to sort your data set.

    public ActionResult Foo(string sort, string sortdir)
    {
        // check if sort = title and then sort your dataset accordingly
        // before returning the model to the view
        ...
    }
    

    The reason sorting works for columns for which you haven’t defined a custom format is because the WebGrid helper is capable to automatically sort the dataset before displaying it, but that’s obviously bad because things like sorting and paging should absolutely be done in your backend layers (like for example in the database if you are using one) in order to have efficient sorting and paging. So even for columns without custom format you should be doing the sorting/paging at the database level instead of relying on the WebGrid helper to sort/page the dataset before displaying.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to populate a WebGrid cell with an image that will open
Creating an item(Under the key) is easy,but how to add subitems(Value)? listView1.Columns.Add(Key); listView1.Columns.Add(Value); listView1.Items.Add(sdasdasdasd);
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a server-side socket will fail if I'm trying to use the same port
Creating a calculator-like dialog, I noticed that quickly clicking on a button in IE
Creating an installer for possible remote systems so that if they do not have
Creating extensions got much easier with Vs2010, but this seems not to be the
Creating a Drawable that is completely empty seems like a common need, as a
Creating an Iphone application, I used to perform INSERT QUERY on different databases. But
Creating a simple TCP server based on examples but still do not get how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.