Sorting not working

Apr 16, 2015 at 2:01 PM
Hi. I can not get my Grid.Mvc to sort. I'm not sure what the problem is, but every time I click on a column to sort it, the page reloads. Can anyone tell me what I am doing wrong? Here is my code:
@Html.Grid(Model.StudentCrsHist).Columns(columns => 
               columns.Add(x => x.YR_CDE)

               columns.Add(x => x.TRM_CDE)

               columns.Add(x => x.SUBTERM_CDE)

               columns.Add(x => x.CRS_CDE)

               columns.Add(x => x.CRS_DIV)

               columns.Add(x => x.CREDIT_HRS)

               columns.Add(x => x.CRS_TITLE)

               columns.Add(x => x.ADD_FLAG)

               columns.Add(x => x.ADD_DTE)

               columns.Add(x => x.DROP_FLAG)

               columns.Add(x => x.DROP_DTE)
Apr 17, 2015 at 9:08 AM
I'm starting to work with this grid and maybe I'm wrong, but I think Grid.Mvc is not an ajax grid so when you sort the data the page reloads showing the data sorted. Are you passing IQuerayable if using Entity Framework to the View instead of IEnumerable?

Best regards
Apr 17, 2015 at 12:42 PM
Ok, so I tried to do this:
public ActionResult Index(int? ID_NUM)
            if (!ID_NUM.HasValue)
                throw new Exception();

            var id = ID_NUM.Value;

            var ViewResults = new CombinedModels();

ViewResults.StudentCrsHist = (from sh in db.StudentCrsHists
                                          where sh.ID_NUM == id
                                          select sh).AsQueryable();
return View(ViewResults);
And in my model I have this
public IQueryable<STUDENT_CRS_HIST> StudentCrsHist { get; set; }
But it still is just reloading the page and nothing shows. Is it maybe because I'm losing the id number when the page reloads? I am using Entity Framework.
May 11, 2015 at 5:44 PM
Has a solution to this been found? I have my grid in a paratialview and when I hit the column header to sort, it reloads the page and the grid/partialview disappears.
May 11, 2015 at 5:46 PM
antman1p, I did not receive a solution for this problem.
May 11, 2015 at 5:58 PM
I'm getting absolutely no feedback on this here, nor on Stackoverflow.
May 20, 2015 at 3:32 PM
You could use this Mvc Grid which supports ajax grid and should work fine with partials.
It has similar API and is at least supported and with less bugs.
May 22, 2015 at 3:24 PM
@hollyquinn - I'm not sure how much help it might be, but for my own use of GridMVC I have employed it successfully (Version both within a regular View and as content inside of a Partial View. One thing I notice that is different between your provided code in the initial post is that you are using the .Add(...) but not .RenderValueAs(...) -- Note, I am unsure (rusty) as to the exact difference, but I know the following works for me (this is from a MVC5 project using EntityFramework 6.0 to function with an Oracle DB - styling via Bootstrap 3.0):

@using GridMvc.Html
@using System.Collections.Generic
@model List<ProjectName.DAL.MODEL_Entity>

    @Html.Grid(Model).Columns(columns =>
            columns.Add().Encoded(false).Sanitized(false).RenderValueAs(o => @<a href="/MODEL_Entity/Edit/@o.ID" class="btn btn-primary btn-xs noDecoration"><span class="glyphicon glyphicon-pencil"></span></a>).SetWidth(15);
            columns.Add().Encoded(false).Sanitized(false).RenderValueAs(o => @<a href="/MODEL_Entity/Delete/@o.ID" class="btn btn-danger btn-xs noDecoration"><span class="glyphicon glyphicon-remove-circle"></span></a>).SetWidth(15);
            columns.Add().Encoded(false).Sanitized(false).RenderValueAs(o => @<a href="#" class="btn btn-default btn-xs noDecoration verifyBtn" onclick="verifyAsset(@o.ID)"><span class="glyphicon glyphicon-ok"></span></a>).SetWidth(15);
            columns.Add(o => o.SERIAL_NUMBER).Titled("Serial #").RenderValueAs(o => o.SERIAL_NUMBER).SetWidth(20);
            columns.Add(o => o.DESCRIPTION).Titled("Desc").RenderValueAs(o => o.DESCRIPTION).SetWidth(20);
            columns.Add(o => o.INVOICE_NUMBER).Titled("Inv. #").RenderValueAs(o => Convert.ToString(o.INVOICE_NUMBER)).SetWidth(20);
            columns.Add(o => o.COST).Titled("Cost").RenderValueAs(o => "$" + o.COST).SetWidth(20);
            columns.Add(o => o.NOTE).Titled("Note").RenderValueAs(o => o.NOTE).SetWidth(20);
            //columns.Add(o => o.CREATED_DATE).Titled("Crtd. Date").RenderValueAs(o => String.Format("{0:MM/dd/yyyy}", o.CREATED_DATE)).SetWidth(20);
            //columns.Add(o => o.CREATED_BY).Titled("By").RenderValueAs(o => o.CREATED_BY).SetWidth(20);
            //columns.Add(o => o.MODIFIED_DATE).Titled("Mod. Date").RenderValueAs(o => String.Format("{0:MM/dd/yyyy}", o.MODIFIED_DATE)).SetWidth(20);
            //columns.Add(o => o.MODIFIED_BY).Titled("By").RenderValueAs(o => o.MODIFIED_BY).SetWidth(20);
This example renders a grid with "buttons"/hyperlinks in the first 3 columns which links to the specific MODEL_Entity instance by passing the ID appropriately to the Edit/Delete Controller Actions. The 3rd column passes the ID to a JavaScript function which uses the ID in JSON to make an Ajax call to a Controller Action and update a specific field in my Database. The rest of the columns are simply an assortment of fields I have used previously, with a few examples of concatenating string characters alongside the rendered values (Ex. Cost), and formatted Date String Values. The .WithPaging(...) can be set as any hard number, but for my own use I have setup my Controller to pass in a Default/User-Selected value via the ViewPage to designate the number of records to show.

Hope it helps!