XSLT DataView filtering with QueryString
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)
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’)
5. In the DataView Filter, select ‘Alphabet’ as column name and value as ‘Alphabet’.
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
Now if you go to your view from the browser, it will filter the rows by the Alphabet!!!!
If somebody wants screenshots for the above steps, please let me know, I will modify this entry. Screen shots added.
hi
can you please post the screen shots too.
thnanks
How would you go about adding an “All” link there so that all employees are listed no matter what their name starts with?
The quickest would be to add a new page without any filter and mimic the look and feel!
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?
Create a new column with this formula and use it for filtering
=ISNUMBER(INT(LEFT([First Name],1)))