Available in the Full Version

Data Grid - Filtering

This sample demonstrates the local simple filtering mode of the igGrid Filtering feature.

Show
records
First NameLast NameRegister DateCountryAgeIs ActiveTime
DownsHolcomb7/25/2015Italy35false8:00 AM
MckenzieCalderon9/22/2014USA26false9:00 AM
HowellHawkins8/8/2015Canada25false8:30 AM
SheppardNicholson6/28/2014Italy49false7:50 AM
BettyeTrujillo4/19/2015Canada37false9:00 AM
JoyceVaughan4/24/2014USA48false8:40 AM
JanineMunoz2/9/2014USA59true10:00 AM
BetsyShort6/4/2015USA26false10:00 AM
TanishaHarrington11/25/2014USA31false11:10 AM
FrenchSullivan8/16/2015Italy37true8:50 AM

This sample is designed for a larger screen size.

On mobile, try rotating your screen, view full size, or email to another device.

By default, simple Filtering mode is inline, which means that all filters are rendered for every column header, below the respective column header cell. From the drop down menu, located above the igGrid, users may also select "Search By Text" option which implies Filter by Text feature. In this scenario, the search is spanned across the entire grid, according to the specific word or phrase entered in the search input. In addition to Filtering feature, local Paging feature is also enabled in this sample.

Code View

Copy to Clipboard
<!DOCTYPE html>
<html>
<head>
	<title></title>

	<!-- Ignite UI for jQuery Required Combined CSS Files -->
	<link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" />
	<link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/structure/infragistics.css" rel="stylesheet" />

	<script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script>
	<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
	<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>

<!-- Ignite UI for jQuery Required Combined JavaScript Files -->
	<script src="http://cdn-na.infragistics.com/igniteui/2024.2/latest/js/infragistics.core.js"></script>
	<script src="http://cdn-na.infragistics.com/igniteui/2024.2/latest/js/infragistics.lob.js"></script>
</head>
<body>
	<!-- Target element for the Simple Filtering igGrid -->
	<label>Switch Filtering Mode:</label>
	<br />
	<input type="text" id="filterType" />
	<table id="gridSimpleFiltering"></table>
	<br />

	 <!--Sample JSON Data-->
	<script src="/data-files/employee-data-allDatatypes.js"></script>

	<script>
		$(function () {
			var f = true, ds, schema;

			schema = new $.ig.DataSchema("array", {
				fields: [
					{ name: "FirstName", type: "string" },
					{ name: "LastName", type: "string" },
					{
						name: "RegistererDate", type: "date", formatter: function (value, record) {
							return value.toLocaleDateString();
						}
					},
					{ name: "Country", type: "string" },
					{ name: "Age", type: "number" },
                    { name: "IsActive", type: "bool" },
                    { name: "RegistererTime" }
				],
			});
			ds = new $.ig.DataSource({
				dataSource: employees,
				schema: schema,
				filtering: {
					type: "local"
				}
			}).dataBind();

			$("#filterType").igCombo({
				mode: "dropdown",
				textKey: "text",
				valueKey: "value",
				dataSource: [
					{ value: "Simple Filtering", text: "Simple Filtering" },
					{ value: "Search By Text", text: "Search By Text" }
				],
				initialSelectedItems : [
					{ value: "Simple Filtering" }
				],
				selectionChanged: function (evt, args) {
					f = args.items[0].data.value === "Simple Filtering";
					createSimpleFilteringGrid(f, ds);
				}
			});
			$(document).delegate("#gridSimpleFiltering", "igcontrolcreated", function (evt, args) {
				if (!f) {
					createSearchField(args.owner, ds);
				}
			});
			createSimpleFilteringGrid(f, ds);
		});
		function createSearchField(grid, ds) {
			var upperPager = grid.container().find(".ui-iggrid-pagesizedropdowncontainerabove"),
				field = $('<input id="filterByText" />');

			upperPager.prepend(field);
			field.igTextEditor({
				placeHolder: "Search...",
				height: "22px",
				textChanged: function (evt, args) {
					ds.filterByText(args.text);
					$(grid.element).igGrid("option", "dataSource", ds.dataView());
				}
			});
		}
		function createSimpleFilteringGrid(f, ds) {
			var features = [
					{
						name: "Paging",
						type: "local",
						pageSize: 10
					}
			];

			if (f) {
				features.push({
					name: "Filtering",
					type: "local",
					mode: "simple",
					filterDialogContainment: "window",
					columnSettings: [
						{
							columnKey: "FirstName",
							condition: "startsWith"
						},
						{
							columnKey: "LastName",
							condition: "equals"
						},
						{
							columnKey: "Country",
							condition: "equals"
						},
						{
							columnKey: "Age",
							condition: "greaterThan"
						}
					]
				});
			}
			if ($("#filterByText").length && $("#searchField").data("igTextEditor")) {
				$("#filterByText").igTextEditor("destroy");
				$("#filterByText").remove();
				$("#searchLabel").remove();
			}
			if ($("#gridSimpleFiltering").data("igGrid")) {
				$("#gridSimpleFiltering").igGrid("destroy");
			}
			$("#gridSimpleFiltering").igGrid({
				autoGenerateColumns: false,
                height: "400px",
                width: "100%",
				columns: [
                    { headerText: "First Name", key: "FirstName", dataType: "string", width: "110px" },
                    { headerText: "Last Name", key: "LastName", dataType: "string", width: "110px" },
                    { headerText: "Register Date", key: "RegistererDate", dataType: "date", width: "150px" },
                    { headerText: "Country", key: "Country", dataType: "string", width: "100px" },
                    { headerText: "Age", key: "Age", dataType: "number", width: "80px" },
                    { headerText: "Is Active", key: "IsActive", dataType: "bool", width: "80px" },
                    { headerText: "Time", key: "RegistererTime", dataType: "time", width: "170px" }
				],
				dataSource: ds.dataView(),
				responseDataKey: "results",
				features: features
			});
		}
	</script>
</body>
</html>