2

I have a webgrid with a date column. The date should appear as a link, plus the column should be sortable too.

If I add the date column like below, the column header "Order Date" is coming up as plain text.

grid.Column(
      header: "Order Date",
      format: (item) => new HtmlString(Html.ActionLink((string)item.orderdate...)
)

If I add the date column without the actionlink, the column header "Order Date" comes up as a link, and I am able to click to sort it.

grid.Column("orderdate", header: "Order Date")

What am I doing wrong? How can I have the column header clickable/sortable and have the date field as a link?

Thanks.

user471317
  • 1,231
  • 2
  • 22
  • 35

2 Answers2

1

Use the columnName attribute.

     columnName: "orderdate";

here is a simple syntax

   grid.Column(
  header: "Order Date",
  columnName: "orderDate",
  format: (item) => new HtmlString(Html.ActionLink((string)item.orderdate...)
  )

and most importantly your columnName should be the EXACT name of the column present in the database

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
0

Add this to your grid

 var grid = new WebGrid(canPage: true, canSort: true);

It will enable sorting

TGH
  • 38,769
  • 12
  • 102
  • 135
  • I have canSort as true. All the other columns are sortable. It's just this one column, and only when I have the action link. Looks like when the data is inside an anchor tag, webgrid doesn't allow sorting on that column. – user471317 Mar 30 '12 at 01:38
  • Could it be that you are wrapping Html.ActionLink in an HtmlString. ActionLink already returns MvcHtmlString, so you shouldn't have to create a new HtmlString – TGH Mar 30 '12 at 01:55