2

I've created a grid using Grid.Mvc. For some reason sorting is not working on it. When I click on the column to sort it, it just reloads the page. I'm very new to MVC and not sure how to fix this. Here is my code.

@Html.Grid(Model.StudentCrsHist).Columns(columns => 
       {               
           columns.Add(x => x.YR_CDE)
               .Titled("YR_CDE")
               .SetWidth(110)                   
               .Sortable(true);

           columns.Add(x => x.TRM_CDE)
               .Titled("TRM_CDE")
               .SetWidth(110)                   
               .Sortable(true);

           columns.Add(x => x.SUBTERM_CDE)
               .Titled("SUBTERM_CDE")
               .SetWidth(110)                   
               .Sortable(true);

           columns.Add(x => x.CRS_CDE)
               .Titled("CRS_CDE")
               .SetWidth(110)                   
               .Sortable(true);

           columns.Add(x => x.CRS_DIV)
               .Titled("CRS_DIV")
               .SetWidth(110)                   
               .Sortable(true);

           columns.Add(x => x.CREDIT_HRS)
               .Titled("CREDIT_HRS")
               .SetWidth(110)                   
               .Sortable(true);

           columns.Add(x => x.CRS_TITLE)
               .Titled("CRS_TITLE")
               .SetWidth(110)                   
               .Sortable(true);

           columns.Add(x => x.ADD_FLAG)
               .Titled("ADD_FLAG")
               .SetWidth(110)                   
               .Sortable(true);

           columns.Add(x => x.ADD_DTE)
               .Titled("ADD_DTE")
               .SetWidth(110)                   
               .Sortable(true)
               .Format("{0:MM/dd/yyyy}");

           columns.Add(x => x.DROP_FLAG)
               .Titled("DROP_FLAG")
               .SetWidth(110)                   
               .Sortable(true);

           columns.Add(x => x.DROP_DTE)
               .Titled("DROP_DTE")
               .SetWidth(110)
               .Sortable(true)
               .Format("{0:MM/dd/yyyy}");
       })
hollyquinn
  • 652
  • 5
  • 15
  • 48
  • **[This link](http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application)** might be helpful – Guruprasad J Rao Apr 17 '15 at 06:19
  • I am having the same issue. I also noticed that my rows do not hightlight when I hover over them. Have you found a solution? – antman1p May 08 '15 at 19:38
  • antman it sounds like you are missing the javascript files. In my project with grid.mvc working I have included: ` ` – Kyle Bachmann Feb 02 '16 at 19:26

2 Answers2

0

You should add the Sortable capabilty to your grid. In your code change the last line to be:

}).Sortable()
Ravid Goldenberg
  • 2,119
  • 4
  • 39
  • 59
0

Try naming your Grid in the declaration, like

@Html.Grid((IEnumerable<project_name.Models.Host>)ViewBag.Hosts).Named("assessmentsGrid").Columns(columns =>

If that does not work I would check your javascript files in your _Layout page. Are you sure you included:

  • ~/Scripts/gridmvc.min.js
  • ~/Scripts/jquery-1.10.2.min.js
  • "~/Content/Gridmvc.css"

Note: I did NOT have to put .Sortable() on my table declaration to get column sorting to work, only had to put .Sortable(true) on my column declarations. My grid ends like }).WithPaging(10).WithMultipleFilters()

I hope this helps you out. Comment if it doesn't we can try something else.

Kyle Bachmann
  • 326
  • 3
  • 16