Search case-insensitive
Search case-sensitive



Click on the "magnifying glass" icon on the bottom toolbar to show the Search Dialog dialog.

Searching (or also sometimes called "Filtering") is supported through the ShowSearchButton option from the ToolBarSettings collection. This will bring a search dialog with common operations (equal, less or equal, greater, not equal, contains), etc.

JQGrid supports several built-in controls for searching - TextBox, DropDown, AutoComplete, DatePicker. The TextBox mode is the default one, you can define DropDowns for search using the EditValues collection. DatePicker and AutoComplete are supported as separate controls - just define them on the page and set the SearchControlID property of the respective column to the ID of the respective JQAutoComplete and JQDatePicker control.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using Trirand.Web.Mvc;

namespace MVCDemo.Models
{
    public class OrdersJqGridModel
    {
        public JQGrid OrdersGrid { get; set; }

        public OrdersJqGridModel()
        {
            OrdersGrid = new JQGrid
            {
                Columns = new List<JQGridColumn>()
                {
                    new JQGridColumn 
                    {
                        // Always set PrimaryKey for Add,Edit,Delete operations
                        // If not set, the first column will be assumed as primary key
                        DataField = "OrderID",                                        
                        PrimaryKey = true,
                        Editable = false,
                        Width = 50,
                        DataType = typeof(int)
                    },                                    
                    new JQGridColumn 
                    { 
                        DataField = "CustomerID", 
                        Editable = true,
                        Width = 100,
                        DataType = typeof(string),
                        ShowColumnMenu = true,
                    },
                    new JQGridColumn 
                    { 
                        DataField = "OrderDate",                                                         
                        Editable = true,
                        Width = 100, 
                        DataFormatString = "{0:yyyy/MM/dd}",
                        DataType = typeof(DateTime),
                        ShowColumnMenu = true,
                    },
                    new JQGridColumn
                    { 
                        DataField = "Freight", 
                        Editable = true,
                        Width = 75,
                        DataType = typeof(double),
                        ShowColumnMenu = true
                    },
                    new JQGridColumn 
                    { 
                        DataField = "ShipName",
                        Editable =  true,
                        Width = 150,
                        DataType = typeof(string)
                    }
                },
                
                Width = Unit.Pixel(640),
                Height = Unit.Pixel(250),
                
                ToolBarSettings = new ToolBarSettings
                {
                    ShowRefreshButton = true
                }
            };  
        }        
    }
}
@model MVCDemo.Models.OrdersGridAndDatePickerModel
@using Trirand.Web.Mvc
@using MVCDemo.Models

<!DOCTYPE html>
<html lang="en-us">
<head>
    <meta charset="utf-8">
    <title>jqGrid for ASP.NET MVC - Search Dialog</title>    
    <!-- jQuery runtime minified -->
    <script src="~/Scripts/jquery-3.2.1.min.js" type="text/javascript"></script>
    <!-- The jqGrid localization file we need, English in this case -->
    <script type="text/javascript" src="~/Scripts/trirand/i18n/grid.locale-en.js"></script>
    <!-- The jqGrid client-side javascript -->
    <script type="text/javascript" src="~/Scripts/trirand/jquery.jqGrid.min.js"></script>    
    <!-- Referece to the javascript client-side code of the jqDatePicker -->
    <script type="text/javascript" src="~/Scripts/trirand/jquery.jqDatePicker.min.js"></script>    
    <!-- Referece to the javascript client-side code of jqAutoComplete  -->
    <script type="text/javascript" src="~/Scripts/trirand/jquery.jqAutoComplete.min.js"></script>  

    <!-- The jQuery UI theme that will be used by the grid. -->
    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.12.1/themes/redmond/jquery-ui.css" />
    <!-- The jQuery UI theme extension jqGrid needs -->    
    <link rel="stylesheet" type="text/css" href="~/Content/themes/ui.jqgrid.css" />   
    
    <style>
        /*the size of the datepicker items*/
        #ui-datepicker-div { font-size: 12px; } 
        /*the size of the autocomplete seach menu for Shipname*/
        .ui-menu-item { font-size: 12px; text-wrap: none } 
	    /*the image that will be shown in the autocomplete input box while performing the search*/
        .ui-autocomplete-loading 
        {
		    background: white url("/content/images/loading.gif") right center no-repeat;
	    }

        /* modify the default autocomplete z-index to appear on top of the search dialog*/
        .ui-front 
        {
            z-index: 1000;
        }
	</style> 
</head> 
<body>
    <br /><br />
   

    @using (Html.BeginForm("SearchDialog", "Grid"))
    {  
        <div style="font-family: Tahoma">
            @Html.RadioButton("searchType", false, !(bool)ViewData["caseSensitive"], new { onchange = "this.form.submit();" })Search case-insensitive<br />
            @Html.RadioButton("searchType", true, (bool) ViewData["caseSensitive"], new { onchange = "this.form.submit();" })Search case-sensitive<br />
        </div>   
    }

    <br/>

    <div>
        @Html.Trirand().JQGrid(Model.OrdersGrid, "SearchDialogGrid")
    </div>
    <!-- this JQDatePicker will be used internally by the grid as DatePicker control for searching and editing -->
    <!-- Datepickers can be used standalone too - when you set the DisplayMode to Standalone (it's the default) -->
    @(Html.Trirand().JQDatePicker(
        new JQDatePicker 
            { 
                DisplayMode = DatePickerDisplayMode.ControlEditor,
                ShowOn = ShowOn.Focus,                    
                DateFormat = "yyyy/mm/dd",                                        
                MinDate = new DateTime(1995,1,1),
                MaxDate = new DateTime(2020,12,21)
            }, "DatePicker")
)
    
    <!-- this JQAutoComplete control will be used internally by the grid as DatePicker control for searching and editing -->
    <!-- AutoCompleters b can be used standalone too - when you set the DisplayMode to Standalone (it's the default) -->
    @(Html.Trirand().JQAutoComplete(
        new JQAutoComplete 
            {
                DisplayMode = AutoCompleteDisplayMode.ControlEditor,
                DataUrl = Url.Action("AutoCompleteShipName","grid")
            }, "AutoComplete")
)    
    <br /><br />
    <div>
                  
    </div>
    
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Trirand.Web.Mvc;
using MVCDemo.Models;

namespace MVCDemo.Controllers.Grid
{
    public partial class GridController : Controller
    {
        // This is the default action for the View. Use it to setup your grid Model.
        public ActionResult SearchDialog(bool? searchType)
        {
            Session["caseSensitive"] = searchType == null ? false : searchType;
            ViewData["caseSensitive"] = Session["caseSensitive"];
            // Get the model (setup) of the grid defined in the /Models folder.
            var gridModel = new OrdersGridAndDatePickerModel();
            var ordersGrid = gridModel.OrdersGrid;
            
            // Setting the DataUrl to an action (method) in the controller is required.
            // This action will return the data needed by the grid
            ordersGrid.DataUrl = Url.Action("SearchDialog_DataRequested");

            // customize the default Orders grid model with custom settings
            // NOTE: you need to call this method in the action that fetches the data as well,
            // so that the models match
            SetUpSearchDialogGrid(ordersGrid);

            // Pass the custmomized grid model to the View
            return View(gridModel);
        }

        // This method is called when the grid requests data
        public JsonResult SearchDialog_DataRequested()
        {
            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new OrdersGridAndDatePickerModel();
            var northWindModel = new NorthwindDataContext();

            // customize the default Orders grid model with our custom settings
            SetUpSearchDialogGrid(gridModel.OrdersGrid);

            // return the result of the DataBind method, passing the datasource as a parameter
            // jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc
            return gridModel.OrdersGrid.DataBind(northWindModel.Orders);
        }

        private void SetUpSearchDialogGrid(JQGrid ordersGrid)
        {
            bool caseSensitive = Session["caseSensitive"] != null ? (bool)Session["caseSensitive"] : false;
            ordersGrid.ToolBarSettings.ShowSearchButton = true;

            var orderIDColumn = ordersGrid.Columns.Find(c => c.DataField == "OrderID");
            orderIDColumn.Searchable = true;
            orderIDColumn.DataType = typeof(int);
            orderIDColumn.SearchOptions = new List<SearchOperation>
            {
                SearchOperation.IsEqualTo,
                SearchOperation.IsGreaterOrEqualTo,
                SearchOperation.IsLessOrEqualTo
            };
           
           
            var orderDateColumn = ordersGrid.Columns.Find(c => c.DataField == "OrderDate");
            orderDateColumn.DataFormatString = "{0:yyyy/MM/dd}";
            orderDateColumn.SearchType = SearchType.DatePicker;
            orderDateColumn.SearchControlID = "DatePicker";  
            orderDateColumn.DataType = typeof(DateTime);                       

            var shipNameColumn = ordersGrid.Columns.Find(c => c.DataField == "ShipName");
            shipNameColumn.SearchType = SearchType.AutoComplete;
            shipNameColumn.DataType = typeof(string);
            shipNameColumn.SearchCaseSensitive = caseSensitive;
            shipNameColumn.SearchControlID = "AutoComplete";
            
            JQGridColumn customersColumn = ordersGrid.Columns.Find(c => c.DataField == "CustomerID");
            customersColumn.Searchable = true;            
            customersColumn.SearchCaseSensitive = caseSensitive;
            customersColumn.DataType = typeof(string);
            
            JQGridColumn freightColumn = ordersGrid.Columns.Find(c => c.DataField == "Freight");
            freightColumn.Searchable = true;
            freightColumn.DataType = typeof(double);
            freightColumn.SearchOptions = new List<SearchOperation>
            {
                SearchOperation.IsEqualTo,
                SearchOperation.IsGreaterOrEqualTo,
                SearchOperation.IsLessOrEqualTo
            };
        }

        public ActionResult SearchDialog_SetCaseSensitive(bool searchType)
        {
            ViewData["caseSensitive"] = searchType;

            return View();
        }
    }
}
Switch theme:


Theming is based on the very popular jQuery ThemeRoller standard. This is the same theming mechanism used by jQuery UI and is now a de-facto standard for jQuery based components. The benefits of using ThemeRoller are huge. We can offer a big set of ready to use themes created by professional designers, including Windows-like themes (Redmond), Apple-like theme (Cupertino), etc. In addition to that any jQuery UI controls on the same page will pick the same theme.

Last, but not least, you can always roll your own ThemeRoller theme, using the superb Theme Editor

To use a theme, simply reference 2 Css files in your Html <head> section - the ThemeRoller theme you wish to use, and the jqGrid own ThemeRoller Css file. For example (Redmond theme):

<link rel="stylesheet" type="text/css" media="screen" href="/themes/redmond/jquery-ui-1.8.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/themes/ui.jqgrid.css" />