Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jul 19, 2015 @ 16:38
    Michaƫl Vanbrabandt
    0

    Get content nodes based on multiple content picker filters umbraco 7

    I have a document type called Career Item which contains some properties and 2 content pickers. one is for selecting a type of career: eg. Driver, the other one is for selecting a branch where the career will be placed: eg. Ghent Belgium.

    My Career types and branches are located in a seperated Content repository, this means they do not have a template, its just a document with properties that can be used on several content pages.

    I have created 2 filters for this and with some jQuery I managed to set the url based on the selection to get urls like:

    http://localhost:59733/nl/vacatures/?f=1075&f=1076&b=1085&b=1082
    

    Here you have f which contains the Career type Ids, and b which contains the Branch Id.

    Now in my razor I am doing the filtering of the content nodes based on the selection but its quite messed up.

    // Collect values for branch and function from the url querystring to perform filtering
    var branch = umbraco.library.RequestQueryString("b");
    // eg: 1085,1082 from example url above
    var function = umbraco.library.RequestQueryString("f");
    

    // eg: 1075,1076 from example url above

    // Take the careers list content node
    var careersList = Umbraco.TypedContentAtRoot().DescendantsOrSelf("CareersList").FirstOrDefault();
    var careerItems = careersList.Children.Where("Visible");
    
    string query = "";
    string funcQuery = "";
    string branchQuery = "";
    
    // Filter on fuction
    if (!String.IsNullOrEmpty(function))
    {
        // Property alias function: content picker
        string[] functions = function.Split(',');
        foreach (string func in functions)
        {
            if (!String.IsNullOrEmpty(funcQuery))
            {
                   funcQuery += " || function == \"" + func + "\"";
            }
            else
            {
                   funcQuery = "function == \"" + func + "\"";
            }
        }
     }
    
      // Filter on branch
      if (!String.IsNullOrEmpty(branch))
      {
           // Property alias branch: content picker
           string[] branches = branch.Split(',');
           foreach (string br in branches)
           {
                 if (!String.IsNullOrEmpty(branchQuery))
                 {
                      branchQuery += " || branch == \"" + br + "\"";
                 }
                 else
                 {
                      branchQuery = "branch == \"" + br + "\"";
                 }
           }
     }
    
     funcQuery = !String.IsNullOrEmpty(funcQuery) ? "(" + funcQuery + ")" : "";
     branchQuery = !String.IsNullOrEmpty(branchQuery) ? "(" + branchQuery + ")" : "";
    
     query = funcQuery + (!String.IsNullOrEmpty(branchQuery) ? " && " + branchQuery : "");
    
     if (!String.IsNullOrEmpty(query))
     {
         careerItems = careerItems.Where(query);
     }
    

    Am I missing something here and could this be simplified? Because now its only 2 filters, but what if i have 5 or 6 filters, then this is not workable...

    /Michael

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 20, 2015 @ 15:07
    Dennis Aaen
    0

    Hi Michael,

    If you are using the Multinode-Treepicker data type the take a look at the documentation for this.

    https://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors-v7/Multinode-Treepicker

    Hope this can help you to achieve what you want.

    /Dennis

  • sandy 4 posts 73 karma points
    Jul 06, 2024 @ 13:08
    sandy
    0

    Hii , Could anyone provide me solution for filter based data show . like I want to create a filter for destination list in which i wan to filter destination from region and country based .

    -My Probelm is here link - http://srecorder.com/s/12wgo

    when I create another package then list of package overide another page at old region page . how can manage filter on this . please provide anybody solution for this .

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies