Filtering and Searching with DataGrid for Silverlight

Posted Tue Nov 17, 2009 @ 10:51 AM

 

As of version 2009.3, ComponentArt DataGrid for Silverlight has out-of-the-box support for searching and filtering, with all the accompanying UI and API control.

To enable filtering through the UI, we set DataGrid's ShowColumnFilters property to true. The availability of a filter dropdown for each column can be further controlled by changing the value of a particular column's ShowFilter property.

To show the search box (in the top-right corner of the header), we set SearchBoxVisibility to Visible and set AllowSearching to true on those columns whose values we wish to consider in the search.

The functionality is accessed in the same way (both UI and API wise) for client-side operation as for integrated web service-based SOA.UI operation. In the former case, the control handles everything automatically, without affecting the data source or requiring any additional code.

In SOA.UI mode, a filter or search request causes a select request to be performed on the SOA.UI service, with filtering information provided in the request data. The convenient ToSqlString method on the Filters collection can be used to generate a SQL WHERE expression in a single step:

public override SoaDataGridSelectResponse Select(SoaDataGridSelectRequest request)
{
  // ... load data into a view (for instance) ...
  DataView view = ...

  view.Sort = request.Sortings.ToSqlString();
  view.RowFilter = request.Filters.ToSqlString();

  // ... create and populate response ... 

  return response;
}

 

The filtering information covers custom filters as well as searches. Searching for a particular string causes the DataGrid control to produce custom filters which produce the desired search, taking into account the AllowSearching property of each column. This allows searching and filtering to be handled at a single point, and typically with a single line of code.

Regardless of the running mode, a search or filter operation can be invoked programmatically by calling DataGrid's Search or FilterBy method respectively:

// filter by last names starting with 'G'
DataGrid1.FilterBy(
  new DataGridDataCondition("LastName", "G", DataGridDataConditionOperand.StartsWith)
  );

// search for 'componentart' occuring in any searchable columns
DataGrid1.Search("componentart");

 

Subsequent paging, sorting and grouping continues to take filters into account until they are removed.

For customizing the styling and content of column filter boxes and dropdowns, we have provided the control-level ColumnFilterHeaderStyle property as well as the column-level FilterHeaderStyle property. The inherent templating ability exposed by the Style allows for full customization of the content.

You can see a demo of this functionality in our Web.UI for Silverlight demo application.

I hope you find this new functionality useful. Let us know what you think!

 

Posted to For the Love of Data by milos

Posted on Tue Nov 17, 2009 @ 10:51 AM

Filed under: , , , , , ,

Comments

Posted on Tue Nov 17, 2009 @ 10:51 AM

A bit of time has passed since we introduced the SOA.UI framework for writing web services that drive

Anonymous comments are not allowed. Click here to log in or create an account.