Page Parameters

If you need to pass some data from your view to your grid, you can use page parameters. Here's how:

NOTE: Page parameters are for static data that will be loaded only once. If you need to pass additional query parameters that could change on the client side, use Additional Query Options
  1. Add one or more names of the page parameters to your grid config: (The names can be anything you want)
        .WithPageParameterNames("Active")
    
  2. Populate the parameter from your view
        @Html.MVCGrid("PPGrid", new { active = "true" })
    
  3. Use the value in your function:
        string ppactive = options.GetPageParameterString("active");
    
Id First Name Last Name
493KarenAdams
897JudithAdams
857MichaelAlexander
55SusanAlexander
190AmyAlexander
250NicholasAllen
472DeniseAllen
870RoseAlvarez
507JuliaAnderson
348AndreaAnderson
Showing 1 to 10 of 493 entries
View
@Html.MVCGrid("PPGrid", new { active = "true" })
Inside MVCGridConfig.cs
MVCGridDefinitionTable.Add("PPGrid", new MVCGridBuilder<Person>(colDefauls)
    .WithAuthorizationType(AuthorizationType.AllowAnonymous)
    .WithPageParameterNames("Active")
    .AddColumns(cols =>
    {
        cols.Add("Id").WithSorting(false)
            .WithValueExpression(p => p.Id.ToString());
        cols.Add("FirstName").WithHeaderText("First Name")
            .WithValueExpression(p => p.FirstName);
        cols.Add("LastName").WithHeaderText("Last Name")
            .WithValueExpression(p => p.LastName);
    })
    .WithPreloadData(true)
    .WithSorting(true, "LastName")
    .WithPaging(true, 10)
    .WithRetrieveDataMethod((context) =>
    {
        var options = context.QueryOptions;
        int totalRecords;
        var repo = DependencyResolver.Current.GetService<IPersonRepository>();
        string ppactive = options.GetPageParameterString("active");
        bool filterActive = bool.Parse(ppactive);
        var items = repo.GetData(out totalRecords, null,null, filterActive, options.GetLimitOffset(), options.GetLimitRowcount(),
            options.GetSortColumnData<string>(), options.SortDirection == SortDirection.Dsc);
        return new QueryResult<Person>()
        {
            Items = items,
            TotalRecords = totalRecords
        };
    })
);