Additional Query Options

You can use the AdditionalQueryOptions to pass any query options you want from client to server. When you click the search button below, it will call the javascript method MVCGrid.setAdditionalQueryOptions with the value of the text box. This will be sent to the server-side with the ajax call and can be accessed in the RetrieveDataMethod.

The below example does not use the parameters but simply shows you how to pass the data that you can access in the RetrieveDataMethod.

The below example sets the values on the client side using the client side api, but it can also be done using client-side bindings

Id First Name Last Name
370PatrickAdams
493KarenAdams
570NancyAdams
599EricAdams
635ChristineAdams
663BonnieAdams
778RonaldAdams
820SeanAdams
897JudithAdams
857MichaelAlexander
Showing 1 to 10 of 1000 entries

Code

Javascript in View
        $(function () {
            $('#searchButton').click(function () {
                MVCGrid.setAdditionalQueryOptions('AQOGrid',
                {
                    param1: $('#parameter1Textbox').val(),
                    param2: $('#parameter2Textbox').val(),
                    param3: $('#parameter3Textbox').val()
                });
            });
        });
        
View
            @Html.MVCGrid("AQOGrid")
        
Inside MVCGridConfig.cs
MVCGridDefinitionTable.Add("AQOGrid", new MVCGridBuilder<Person>(colDefauls)
    .WithAuthorizationType(AuthorizationType.AllowAnonymous)
    .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);
    })
    .WithAdditionalQueryOptionNames("param1", "param2", "param3")
    .WithAdditionalSetting("RenderLoadingDiv", false)
    .WithSorting(true, "LastName")
    .WithPaging(true, 10, true, 100)
    .WithRetrieveDataMethod((context) =>
    {
        var options = context.QueryOptions;
        int totalRecords;
        var repo = DependencyResolver.Current.GetService<IPersonRepository>();
        string param1Value = options.GetAdditionalQueryOptionString("param1");
        string param2Value = options.GetAdditionalQueryOptionString("param2");
        string param3Value = options.GetAdditionalQueryOptionString("param3");
        var items = repo.GetData(out totalRecords, null, options.GetLimitOffset(), options.GetLimitRowcount(),
            options.SortColumnName, options.SortDirection == SortDirection.Dsc);
        return new QueryResult<Person>()
        {
            Items = items,
            TotalRecords = totalRecords
        };
    })
);