2008-08-06

Filtering SharePoint List Libraries with Web Part Filters



Sometimes you need to filter data (ListViews/DataViews/Other web parts) based on some criteria be it the persons name, their email, a specific date range or from a parameter.

Microsoft provide a number of these Web Parts called filters. The problem is they only provide these in the Enterpri$e ver$ion.


So I made my own and I'm sharing them with you....


ray1.net Web Part Filters feature is comprised of 6 web parts.





  1. ray1.net Content Connector. This is a simple Literal Control that renders the value of a connection, or the text you specify. You can use it with, say the UserFilter and render some text that says "Welcome to my site UserFilter value!"

  2. ray1.net Filter Web Part: Current Page. This web part provides a filter connection that send information about the current page. The page needs to be in a list. You can use this to filter content based on who created the page or the file size or the modified date.


  3. ray1.net Filter Web Part: Date. This web part provides a filter connection that sends information about a selected date or date range. Say you had a DataView web part that sent a parameter to an SQL stored procedure.


  4. ray1.net Filter Web Part: QueryString. This filter accepts a QueryString parameter and connects to another web part. Pretty simple really, name the filter the same as the querystring parameter and your done.

  5. ray1.net Filter Web Part: User Name. This web part provides a User Name connection filter. This web part makes this feature incompatible with WSS v3, as I use the "Microsoft.Office.Server.UserProfiles.UserProfileManager" class.


  6. ray1.net Filter Web Part: Web ID. This web part provides a filter connection that sends the Web ID. Another simple one, but useful... Say you have a bunch of sites using the same template and you wanted to filter an SQL query.


All the filters accept multiple connections, and this is what they look like in edit mode.





This is what they look like normally





Download link: ray1.net Web Part Filters

To do: I could add a Text Filter and maybe change the Content Connector to accept n number of connections.



Keywords: Filter, web part, listview, SPSlicerBaseWebPart, ToolPart, IWebPartField, GetConnectionInterface, Connection Consumer Provider


8 comments :

  1. This looks like a great webpart however i have one question, you state in your todo "I could add a Text Filter and maybe change the Content Connector to accept n number of connections" So at the moment you can only use one filter on a list?
    This is also in the enterprise version where you can place one webpart only to connect to a list.

    ReplyDelete
  2. Hey buks, no; the content connector wp is part of this package, and when I developed it I made it to accept 1 connection from another web part... the "filter" wp will connect to any number of wp's.

    HOWEVER a ListView wp only accepts 1 connection too, nothing I can do there.

    ReplyDelete
  3. Hi Rey,

    this is a fantastic web part.
    I tried to use a date range filtering. after I setup everything. and try to connected to Sharepoint's list. Sharepoint raise an error about

    Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))


    Any way to solve this ?

    regards,

    Pp

    ReplyDelete
  4. Hi PP... this is usually a permissions issue. Can you set customErrors mode="Off"

    In you web.config, and post the whole error message?
    When did it happen before or after connecting to the list?
    Do the other filters work?

    ReplyDelete
  5. Hi Ray,

    I restore my image back to original. now I can added your web part.

    the question is I would like to filter the list which date range. I tried to input start and end date.
    And the 2 web part are connected.
    the filter does not apply with my list.

    could you pls help

    cheers,
    PP

    ReplyDelete
  6. The date range passes a cross a string like: yyyy-mm-dd,yyyy-mm-dd

    So you'll either have to connect it to a calculated field or create your own listview webpart that can split the string.

    I couldn't think of anyway of doing it so that it works with an OOTB list view... cos the listview only accepts 1 connection.

    ReplyDelete
  7. Hi Ray,

    could you pls give me your hands.

    I create a simple Sharepoint list.
    and also I create a new calculated field with "Created" of default sharepoint. the new calculated fields is myDate, format to yyyy-mm-dd.

    also I apply your web path date range with this fields. it still does not works.

    Cheers,

    ReplyDelete
  8. Can you please share how can I make it work your date range web part in SharePoint document library.

    ReplyDelete