# Angular Grid Manual Filtering

The manual filtering gives the developer full control over the filtering of the data. Compared to the [filtering with the built-in directive](https://www.telerik.com/kendo-angular-ui-develop/components/grid/filtering/basics#using-the-built-in-directive), the manual approach provides greater transparency of the filtering process because it requires you to handle the [Angular Grid](https://www.telerik.com/kendo-angular-ui-develop/components/grid) events manually. The manual filtering is especially useful when you require additional customization of the filtering logic.

To implement manual filtering:

1. Set the [filterable](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#filterable) option.
2. Bind the [filter](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#filter) option to a [`CompositeFilterDescriptor`](https://www.telerik.com/kendo-angular-ui-develop/components/data-query/api/compositefilterdescriptor) object.
3. To filter local data or send a remote service request, handle either of the following events:
   * [`filterChange`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#filterchange) event—use it when only filtering is enabled.
   * [`dataStateChange`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#datastatechange) event—use it when more than one data operation is enabled. For more details, check the section on how to [handle multiple data operations](https://www.telerik.com/kendo-angular-ui-develop/components/grid/data-operations#handling-multiple-data-operations).

## Filtering Local Data

To filter the data, use the built-in [`filterBy()`](https://www.telerik.com/kendo-angular-ui-develop/components/data-query/api/filterby) or [`process()`](https://www.telerik.com/kendo-angular-ui-develop/components/data-query/api/process) functions.

> When you enable multiple data operations, handle the `dataStateChange` event instead of the `filterChange` event and use the `process()` method. Further details on how to manually process the data with multiple data operations enabled are available in the section on [handling multiple data operations](https://www.telerik.com/kendo-angular-ui-develop/components/grid/data-operations#handling-multiple-data-operations).

The following example demonstrates this approach.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/data-operations/filter-change/source.txt)

## Server-Side Filtering

To filter data on the server, send the descriptor that the Grid provides to your data service. Handle [`filterChange`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#filterchange) when filtering is the only enabled data operation. Handle [`dataStateChange`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#datastatechange) when filtering is combined with paging, sorting, or grouping.

The backend must apply the received filter descriptor and any other requested data operations to the data source. Return a [`GridDataResult`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/griddataresult) that contains the filtered data and the total number of matching records. The Grid uses the total count to render the pager correctly.

To process the data on the server:

1. Convert the Grid [`State`](https://www.telerik.com/kendo-angular-ui-develop/components/data-query/api/state) to a request string with [`toDataSourceRequestString`](https://www.telerik.com/kendo-angular-ui-develop/components/data-query/api/todatasourcerequeststring), and send it to the data service.

   ```ts
   public fetch(state: State): Observable<GridDataResult> {
       const request = toDataSourceRequestString(state);

       return this.http.post<GridDataResult>(this.baseUrl, request, {
           headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
       });
   }
   ```

2. Bind the request to `DataSourceRequest` and pass it to [`ToDataSourceResult`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.extensions/queryableextensions#todatasourceresultsystemdatadatatablekendomvcuidatasourcerequest). Import `Kendo.Mvc.Extensions` and `Kendo.Mvc.UI` to use these APIs.

   ```C#
   [AcceptVerbs("Get", "Post")]
   public IActionResult Get([DataSourceRequest] DataSourceRequest request)
   {
       return Json(this.context.Customers.ToDataSourceResult(request));
   }
   ```

   > To use `ToDataSourceResult`, install the Telerik ASP.NET MVC UI NuGet package source. Follow [Installing Telerik UI for ASP.NET MVC Using NuGet Packages](https://www.telerik.com/aspnet-mvc/documentation/installation/installation-options/nuget-install) or the [.NET CLI installation guide](https://www.telerik.com/blazor-ui/documentation/installation/nuget#use-the-net-cli).

3. Return the processed records and their total count as the JSON response. For a production data source, apply `ToDataSourceResult` directly to the data query, as shown by the [CustomersController](https://github.com/telerik/kendo-ui-demos-service/blob/5f254f1e959cd41a41ec69669cb36c7b7075ecd6/graphql/graphql-aspnet-core/graphql-aspnet-core/Controllers/CustomersController.cs).

The following example runs this flow against the demos service, using the [ServerOperationsController](https://github.com/telerik/kendo-ui-demos-service/blob/5f254f1e959cd41a41ec69669cb36c7b7075ecd6/graphql/graphql-aspnet-core/graphql-aspnet-core/Controllers/ServerOperationsController.cs). Review the [GraphQL ASP.NET Core demos service](https://github.com/telerik/kendo-ui-demos-service/tree/5f254f1e959cd41a41ec69669cb36c7b7075ecd6/graphql/graphql-aspnet-core/graphql-aspnet-core) for the complete server implementation.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/data-operations/remote-data/source.txt)

For a runnable local example and setup guidance for server-side data operations in ASP.NET Core with the Grid and Upload components, see [Kendo UI for Angular Integration with ASP.NET Core](https://www.telerik.com/kendo-angular-ui-develop/components/installation/dotnet-core#handling-grid-data-operations). For Java Spring Boot data operations, see [Kendo UI for Angular Java Spring Boot Integration](https://www.telerik.com/kendo-angular-ui-develop/components/installation/java-spring-kendo-angular-integration#handling-grid-data-operations).

## Suggested Links

* [FilterDescriptors](https://www.telerik.com/kendo-angular-ui-develop/components/data-query/api/filterdescriptor)
* [dataStateChange](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#datastatechange)
* [Built-In Row Filter Templates](https://www.telerik.com/kendo-angular-ui-develop/components/grid/filtering/filter-row)
* [Built-In Menu Filter Templates](https://www.telerik.com/kendo-angular-ui-develop/components/grid/filtering/filter-menu)
* [Reusable Custom Filter Components](https://www.telerik.com/kendo-angular-ui-develop/components/grid/filtering/filter-row#custom-filter-row-components)
* [Data Binding Basics](https://www.telerik.com/kendo-angular-ui-develop/components/grid/data-binding/basics)
* [Automatic Data Processing](https://www.telerik.com/kendo-angular-ui-develop/components/grid/data-binding/local-data#automatic-data-processing)
* [API Reference of the GridComponent](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent)
