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.

26 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?

Stephen J. Naughton 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

Stephen J. Naughton 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.

Stephen J. Naughton 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.

Stephen J. Naughton 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!

Anonymous said...

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

Stephen J. Naughton 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.

Stephen J. Naughton 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? :)

Stephen J. Naughton 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!

JP said...

Where can I download the examples ? I can't find any links here

JP said...

Could you post the link again please ? The one on SkyDrive does not seem to work : CustomFilters.zip

Btw, I had trouble posting a comment here

Stephen J. Naughton said...

yes Microsoft did some changes to SkyDrive and ALL my links stopped working try this link
https://skydrive.live.com/embed?cid=96845E7B0FAC1EED&resid=96845E7B0FAC1EED%21112&authkey=AAK2BRsHZauGw-0

it will take you to my public folder where all my samples are.

Steve

JP said...

Thanks a lot !
Really useful website !

Stephen J. Naughton said...

your welcome JP, I will be including them in my Bootstrap friendly project template sometime soon.

Steve

Unknown said...

Hi Steve,

Thanks for detailed article. I am using DD for one of my application where I need to display the data from database which is based on either "logged in user" or the "company of logged in user". What would be the easiest way to implement? is there any way that i can modify Metadata class to restrict the records displayed from particular table? thanks in advance

Stephen J. Naughton said...

Hi Prabhakar, there are two areas of security you will need to look at.
1. what the user can see, i.e. which tables and columns etc.
2. what data they can see.

for the first I have an article on my blog about that and for the second it's a log more complex I do have something in the works but it's not ready yet will try and get an article ready soon.

Steve

Unknown said...

Hi Steve,

This is Sudhakar. I communicated with you last on Wijmo tab and Accordion. I could make them work some how. I am working with the custom filters now. I could make it to work. However, I would need calendar controls for date range to show up and also drop down for full text search on a particular column using its distinct values. Could you please throw some light on how to achieve them?

With kind Regards,
Sudhakar

Stephen J. Naughton said...

What version of Asp.Net are you running?