Sunday, 21 November 2010

Five Cool Filters for Dynamic Data 4

Starting with the Range Autocomplete, Range & MultiForeignKey Filters from the old Dynamic Data Preview 4 Refresh, I have also added five of my filters:

  1. DateRange
  2. StartsWith
  3. EndsWith
  4. Contains
  5. Where

I won’t go into much detail here as Oleg Sych has done this great series on DD4 filters, that pretty much explains it all for you.

I am using the Ajax Control Toolkit for the date picker in the DateRange filter but other than that it’s not much different form the Range filter from the Dynamic Data Preview 4 Refresh sample.

!Important: One thing I would like to point out is that both Entity Framework and Linq to SQL have a small but important issue. This issue is the the “Contains” Expression used in the above filter of the same name is actually expressed as the “Like ‘%{0}%’” and so you DO NOT get full text search using “Contains”.

“Contains” when it was introduced in SQL Server 7 was given a big build up and to be omitted in EF and L2S is a big let down.

Some examples:

Other Filters

Figure 1 – DateRange, StartsWith, EndsWith, Contains, Where and AutoComplete filters

Range and Multi Select Filters

Figure 2 – Range and Multi Select Filters

I just thought that these filters would be useful for your tool boxes.

!Important: I can’t take credit for all the Expression helpers most come from the above mentioned Preview 4 that is no longer on the ASP.Net Codeplex site.
Download

Note I’ve included my five filters and the three filters from the Preview.

As always happy coding.

17 comments:

Tali Av said...

hi, when I run costomFilters ,
its fails on sql connection ?
but the northwind is in the projects so why it fails?

Tyler said...

Stephen, I'm loving your blog entries on Dynamic Data. Of the resources I've found so far, yours cover the most ground and I've made solid progress in just a couple days.

Quick question (I think) related to this article :

I'm trying to use the autocomplete filter from this article. But does it have to be applied to a foreign key column? Can it be modified to work with a general column and pull a list of possible values directly from there? If so, how might I do that?

Also a more general question:
I've been trying to figure out how to generate metadata for all columns by querying a definitions table from in SQL (which I would create to include display names, filter options, etc). Would you have any suggestions where I could find information on accomplishing that?

Steve said...

see my http://csharpbits.notaclue.net/2008/07/dynamic-data-and-field-templates_28.html article it's for DD1 but you should be able to modify the DD4 verion similarly.

Steve

Steve said...

See Marcin's InMemoryMetadata provider in the old DD futures project on aspnet.codeplex.com

Steve

Anonymous said...

Hello Steve
I am trying to use Range Filter to Filter string type.
It seems BinaryExprssion donesnt work on string format.
What I want to do is something like
"ProductId Between '001' AND '004'"

Any Suggestion?
Thank You
James

Anonymous said...

It would be great if someone would provide a sample of a "Contains" filter without making use of the LinqExpressionHelper class. It would be easier to understand.

Steve said...

Sorry why would you want to do the work someone else already did the source code is there with comments :)

Steve

Brent V said...

Your blog is GREAT! You have so much useful stuff on Dynamic Data. I have learned so much from you. The download for this post was super easy to use and plugged right into my Dynamic Data 4 application. I like your implementation too.

Steve said...

Hi Brent, I plan on making ALL my stuff available over time via NuGet

Steve

Brent V said...

Steve, That would be GREAT to see it in NuGet!

yannick said...

Would be cool if the Where filter would also allow for filtering PK fields (Int32). Currently it gives an error.

Steve said...

I'll have a look at that but it shouls work with a little tweaking.

Steve

redevolve said...

Hi Steve, could you please recommend any references for this.

I have table Company, and a company may have one or many Employees. I then have a gridview to list Companies on my List.aspx. I wanted to add a filter called, "Employee Name" on this List page.

P/s: My entity data source on the Companies gridview has this property: Include="Employees".

I am on EF and DD4. My Company entity does have a Navigation property to Employee. I've checked your MultiColumnSearch but it does not allow child table's columns access.

Or if you have any workarounds, that'd be great too.
Thanks.

Steve said...

Hi There, can you e-mail me direct please :) my e-mail is in the top right of the page.

Steve

szilagyi szabi said...

hi! how can I add a "Not Set" option to MultiForeignKey filter? :)

Steve said...

The [Not Set] option is there already but does not show if the FK column is required this is because there will never be a null value under those conditions

Steve

szilagyi szabi said...

thanks for the quick reply!