locked
A filter based on a lookup column RRS feed

  • Question

  • Hi,

    I have a list based on a custom content type which contains a lookup column. I need to create a view that would allow me to dynamically select a value for the lookup field and filter the list based on the selected value.

    On the Edit View screen I can see a Filter section with an option "Show items only when the following is true". It looks like this is what I need but it allows me to hard-code lookup values while I need to be able to select the lookup values and filter the list dynamically.

    After I know how to do that on UI, I will need to create C# code that would create such a "dynamic" view programmatically.

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Friday, April 15, 2016 4:35 PM

Answers

  • Wow finally I think I got your requirement.

    You need to add the "SharePoint List Filter" to the page above your list which consumes the lookup column. In the SharePoint list filter, configure to show the lookup column from the categories list (per your example), enable webpart connections from the list filter webpart.

    It should look like below, categories list lookup column can be selected and filters the list below. In this case I have select value A and it filters my second list which consumes it.

    Here is the YouTube video for adding SharePoint list filter and connecting to list view. Its for SP 2010, but nothing much changed on that.


    ---
    Rajesh | Blog


    • Edited by Rajesh.Sitaraman Monday, April 18, 2016 9:56 PM added YouTube link
    • Proposed as answer by Victoria Xia Wednesday, April 20, 2016 1:29 AM
    • Marked as answer by ata6502 Thursday, April 21, 2016 2:51 PM
    Monday, April 18, 2016 9:38 PM

All replies

  • Use querystring filter on the list view columns like below

    http://yoursite/sites/rajesh/Lists/SecondList/AllItems.aspx?FilterField1=Application&FilterValue1=A


    ---
    Rajesh | Blog

    Friday, April 15, 2016 7:07 PM
  • Thanks Rajesh. It looks like it may solve my problem. Could you elaborate on how you created the "filter column"? I assume that the values for this column come from my custom list. How to point the filter to my list?

    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Monday, April 18, 2016 5:59 PM
  • What exactly you are going to do with that dynamic view? Are you creating multiple views in the list using C#, or trying to get the list items from the filtered view? or providing some sort of the links (to navigate) in your webpart/page?

    ---
    Rajesh | Blog

    Monday, April 18, 2016 6:12 PM
  • I'm trying to create a single view that would be filtered using values from a lookup field.

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Monday, April 18, 2016 7:24 PM
    1. Create a view with your columns to be shown, get the view url from the address bar
    2. Add the querystring to viewurl "?FilterField1=YourColumnTitle&FilterValue1=YourColumnValue

    Like 

    http://yoursite/Lists/yourlist/AllItems.aspx?FilterField1=columnname&FilterValue1=columnvalue

    replace, 

    yoursite with the site url, yourlist with the list title, columnname with the lookup column name from list which want to filter, columnvalue with the value to want to apply for the filter


    ---
    Rajesh | Blog

    Monday, April 18, 2016 8:34 PM
  • Thanks Rajesh for your response.

    It seems that your solution is not what I need. I don't want to hard-code anything. I simply don't know the 'columnvalues' (from your example). This is something that the user will create in a separate list - let's call it "Categories".

    The list I want to filter has a lookup column that takes values from the Categories list. I need to allow the user to pick a Category and use it to filter items in the list.

    Your solution hard-codes Categories in a query string.

    Am I clear enough?

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Monday, April 18, 2016 8:50 PM
  • Wow finally I think I got your requirement.

    You need to add the "SharePoint List Filter" to the page above your list which consumes the lookup column. In the SharePoint list filter, configure to show the lookup column from the categories list (per your example), enable webpart connections from the list filter webpart.

    It should look like below, categories list lookup column can be selected and filters the list below. In this case I have select value A and it filters my second list which consumes it.

    Here is the YouTube video for adding SharePoint list filter and connecting to list view. Its for SP 2010, but nothing much changed on that.


    ---
    Rajesh | Blog


    • Edited by Rajesh.Sitaraman Monday, April 18, 2016 9:56 PM added YouTube link
    • Proposed as answer by Victoria Xia Wednesday, April 20, 2016 1:29 AM
    • Marked as answer by ata6502 Thursday, April 21, 2016 2:51 PM
    Monday, April 18, 2016 9:38 PM
  • Thanks Rajesh. We are almost there :)

    The thing is that I don't have a Page tab in my ribbon that would allow me to add a web part. I have a Library tab because I'm using the standard page AllItems.aspx. Is there any way to have this kind of dynamic filtering on the library rather than on a page?

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Tuesday, April 19, 2016 7:08 PM
  • If you appropriate permissions, then click on the gear icon on the right then you should be able to see the edit page in the menu, when you hit edit page, you'll be able to see the page tab in the ribbon and also option to add webparts.

    If it doesn't work, then create a new page and add your list to that page and configure the view accordingly and then you can add the SharePoint list filter webpart on that page.


    ---
    Rajesh | Blog

    Tuesday, April 19, 2016 7:24 PM
  • Great! Thanks Rajesh. This is what I needed. I have marked your answers as helpful.

    I know how to create the filter from SharePoint UI. Now, I need to create this filter programmatically. It looks like the steps are as follows:

    - Add a SharePoint List Filter web part to my library/page.

    - Configure the filter: provide list URL and value field.

    - Connect the filter to my library.

    There are two reasons why I need to do it programmatically:

    - I'm creating my library (actually several libraries) programmatically. Hence I'm not able to add the web part manually in advance.

    - I need to deploy this solution to multiple environments. I don't want to configure the web part in each and every of them.

    Could you guide me how I can accomplish the same feat but programmatically?

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Tuesday, April 19, 2016 8:16 PM
  • Hi Leszek,

    You can add the filter web part to the page and then setup the connection programmatically.

    About how to add a web part to a page programmatically:

    http://www.sharepointdiary.com/2012/08/how-to-add-web-parts-to-the-page-programmatically.html

    About how to add web part connection programmatically:

    http://jcapka.blogspot.sg/2010/06/connecting-xsltlistviewwebparts.html

    http://sharepoint-insight.blogspot.sg/2008/09/sharepoint-using-splimitedwebpartmanage.html

    If you think the reply is helpful, you can mark it as answer and it will help others who meet the same issue in this forum.

    Best Regards,

    Victoria

    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.


    Thursday, April 21, 2016 6:38 AM
  • Thanks Victoria. Yes, the links are helpful. I have marked your answer as helpful.

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Thursday, April 21, 2016 2:51 PM