This project has moved and is read-only. For the latest updates, please go here.

FilterDropdown from top level site

Feb 12, 2015 at 9:30 PM
I am fairly new to SharePoint, but have used the jQuery library in other environments.

I'm trying to set up a cascading dropdown inside a subsite, using lists from the top level site. I've gone through many of the posts here, but can't get it working in my site collection. I keep getting a server 500 error related to _vti_bin/Lists.asmx. I've tried using the SPCascadeDropdowns function and the SPFilterDropdown.

The scenario is that in the top level site, I have a list "MainCat" for main categories. I have another list "SubCat" that has a title column and then a lookup to the MainCat list to create a relationship to sub categories. Both lists use "Title" for the primary column. In the SubCat list, there is a column "MainCat".

In the subsite, I have a list in which I would like the cascading dropdown list based on the SubCat list from the top level site.

Using the SPFilterDropdown function, my code is:

$(document).ready(function() {
alert("jQuery is here");

   columnName: "MainCat",
   completefunc: null,
   debug: true

var field = $("nobr:contains('MainCat')").closest("tr");
var itemMain = $(field).find("select");
    //var mainCtgy = $( "itemMain option:selected").text();

function ChangeOptions(mainCtgy){
var topCtgy = $(mainCtgy).val(); // get the main category that was selected

var mainTxt = $(mainCtgy).find('option:selected').text();

var myQuery = "<Eq><FieldRef Name='MainCat' /><Value Type='Choice'>"+mainTxt+"</Value></Eq>";

alert("Got to function");
alert("value is: " + topCtgy);
alert("text is: " + mainTxt);

alert("caml is: " + myQuery);

    relationshipWebURL: "/sites/mk_sites/",
    relationshipList: "SubCat",
    relationshipListParentColumn: "MainCat",
    relationshipListSortAscending: true, 
    relationshipListSortColumn: "Title",
    columnName: "Title",
    listName: $().SPServices.SPListNameFromUrl(),
    promptText: "",
    noneText: "(None)",
    CAMLQuery: myQuery,
    CAMLQueryOptions: "<QueryOptions></QueryOptions>",
    completefunc: null,
    debug: false

The alerts are all coming through; the subcat dropdown does not filter though.

Any help would be most appreciated!
Feb 13, 2015 at 5:06 AM
Edited Feb 13, 2015 at 5:10 AM
SPFilterDropdown doesn't work that way. You can only call it once, and it filters based on the criteria you pass in. In other words, subsequent calls with different filters won't work.

You could certainly clone the function and alter it to meet your needs. But I think you probably want SPCascadeDropdowns?

In any case, don't call the function passing in the defaults. You only need this:
    relationshipWebURL: "/sites/mk_sites/",
    relationshipList: "SubCat",
    relationshipListParentColumn: "MainCat",
    columnName: "Title",
    CAMLQuery: myQuery
Feb 13, 2015 at 1:16 PM
Thanks so much! I had tried the SPCascadeDropdowns earlier and was getting the 500 error. I tried it again today using the GUID of the relationship list rather than the name, and it works beautifully. And thank you for such a great tool -- it's fantastic.
Feb 13, 2015 at 1:51 PM
The name of the list should work, but you may also need to specify the relationshipWebURL.