XSLT DataView filtering with QueryString

July 23rd, 2009 | Tags:

Update: Screen Shots added as per request!

One of the challenges we faced while building an Employee directory with SharePoint is to have an Alphabetical search function. (No, no, I am not talking about using the User Profile to build the Employee Directory. This is purely a user maintainable list)

All the contacts are entered into a single list and when the user clicks the corresponding Alphabet, it should filter dynamically and show the corresponding ones. Ok, you can do that by creating individual views for each alphabet, but that would end up in a lot of work if we want to change something.

Hence, the approach we took is as follows:

1. Create a calculated column ‘Alphabet’ which will be the first alphabet of the First Name. For beginners, you can use the function =LEFT([First Name],1)

image

2. Create a new View with the columns you want to display (say ‘AlphabetView.aspx’).

3. Open this in SharePoint Designer and convert this into an XSLT view.

4. Right click the DataView, select Properties and create a new parameter, say ‘Alphabet’. Set this parameter to take from the QueryString (say ‘Alphabet’)

image

5. In the DataView Filter, select ‘Alphabet’ as column name and value as ‘Alphabet’.

image

6. In the Alphabet links, make sure you pass the QueryString value along with the page name.

e.g. http://abcd.com/Lists/Contacts/AlphabetView.aspx?Alphabet=A

image

Now if you go to your view from the browser, it will filter the rows by the Alphabet!!!!

image

If somebody wants screenshots for the above steps, please let me know, I will modify this entry.  Screen shots added.

Technorati Tags:
  1. hk04
    October 20th, 2009 at 13:41
    Reply | Quote | #1

    hi
    can you please post the screen shots too.

    thnanks

  2. Lax13
    April 12th, 2010 at 14:52
    Reply | Quote | #2

    How would you go about adding an “All” link there so that all employees are listed no matter what their name starts with?

  3. admin
    April 13th, 2010 at 03:44
    Reply | Quote | #3

    The quickest would be to add a new page without any filter and mimic the look and feel! ;)

  4. Winterman
    April 26th, 2010 at 02:45
    Reply | Quote | #4

    This is perfect for something I am doing at the moment – thanks! Just one thing, I also need to be able to filter on all items that start with a number? Any advice on adding that please?

  5. admin
    April 26th, 2010 at 03:04
    Reply | Quote | #5

    Create a new column with this formula and use it for filtering
    =ISNUMBER(INT(LEFT([First Name],1)))