3

I have a Grid.MVC based list which allows me to create a sortable, filterable, paged list.

Problem is, I can't seem to find anything in the documentation for Grid.MVC in particular to ouput a "count" of what has been filtered. I figured you may need a client side solution through potentially some jQuery code, but I was hoping maybe there was something easier.

@using GridMvc.Html
@model IEnumerable<Sample.Cases>

@{
    ViewBag.Title = "Case Browse List";
}

<h2>Case Browse List</h2>

<p>
    @Html.ActionLink("Add New Participant", "Create")
</p>

<div>
    @Html.Grid(Model).Columns(columns =>
                    {
                        columns.Add().Encoded(false).Sanitized(false).SetWidth(30).RenderValueAs(model => @<b>@Html.ActionLink("Select", "Details", new { id = model.ID })</b>);
                        columns.Add(model => model.ID).Titled("ID");
                        columns.Add(model => model.FirstName).Titled("First Name");
                        columns.Add(model => model.MiddleName).Titled("Middle Name");
                        columns.Add(model => model.LastName).Titled("LastName");
                        columns.Add(model => model.LKPSuffixes.SuffixDescription).Titled("Suffix");
                        columns.Add(model => model.LKPCaseStatuses.CaseStatusDescription).Titled("Case Status");
                        columns.Add(model => model.CaseStatusDate).Titled("Case Status Date");
                    }).WithPaging(10).Sortable(true).Filterable(true).WithMultipleFilters()
</div>

Above is my view, it's quite simple, but I basically just need a footer below this grid that states how many results we have in total. This is filterable and paginated, so it should get a count of all records, not just the 10 displayed (.WithPaging(10)) or the total without filtering by anything in the columns.

Grid.MVC has a sample project very much like this here: http://gridmvc.azurewebsites.net/?grid-page=3

Edit - Ideally, the footer might say something like "Showing 1 to 10 of 57 entries", or if that's not possible, even just the total entries would do fine for our requirements.

Reading some of this code in their GitHub - it appears there are some attributes for the count of displayed or total rows (after filtering), so I feel like there must be some built-in way to do this, just not sure how.

https://github.com/leniel/Grid.Mvc/blob/master/GridMvc/IGrid.cs

aohm1989
  • 401
  • 1
  • 8
  • 19
  • take a look at this: 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. Is a good tutorial which shows how to use PagedList.MVC combined with GridMvc. Take a look to the Add Paging to the Students Index Page section – user2232273 Jan 27 '16 at 17:06

1 Answers1

6

There's an option .WithGridItemsCount(string gridItemsName) which allows you to display the total count.

So you can set something like -

.WithPaging(15).WithGridItemsCount("Total Orders")

Here's the output -

enter image description here

vendettamit
  • 14,315
  • 2
  • 32
  • 54
  • Interestingly, I did not have "WithGridItemsCount" - I think the NuGet package may not be as up to date as what is in GitHub (NuGet seems to be v3.0). Probably when getting this updated, I can then use this option. – aohm1989 Jan 27 '16 at 17:25
  • 3
    Yup! 3.0 does not have this option. You can install pre-release 3.1 to get this feature https://www.nuget.org/packages/Grid.Mvc/3.1.0-ci1036 – vendettamit Jan 27 '16 at 17:30
  • Yep that fixed it (had to do a little tweaking in "unchecking" the machine-wide package source to install the -Pre version via command line) - thanks! – aohm1989 Jan 27 '16 at 18:40