Quantcast
Channel: jQuery Library for SharePoint Web Services
Viewing all articles
Browse latest Browse all 6517

New Post: Cascading lookup - child drop-down not filtering

$
0
0
Hi Mark,
Unfortunately, the way your lists are structured, especially with using a site column, is not compatible with the cascading dropdown function. However, I drafted and tested the code below, which uses the SPFilterDropDown function instead, and is triggered whenever the user changes the "PCYC Club" selection in the "Participants" list. Please see the annotations below the code for guidance and an explanation on how to apply it to your situation.

1 <script src="/javascript/jquery-1.8.3.js" type="text/javascript"></script>
2 <script src="/javascript/jquery.SPServices-0.7.2.js" type="text/javascript"></script>
3 <script src="/javascript/spjs-utility.js" type="text/javascript"></script>
4 <script language="javascript" type="text/javascript">
5
6$(document).ready(function() {
7
8 $().SPServices.SPComplexToSimpleDropdown({
9 columnName: "Center",
10 completefunc: null,
11 debug: true
12 });
13
14 var field = $("nobr:contains('PCYC Club')").closest("tr");
15 var itemClub = $(field).find("select");
16 $(itemClub).change(function(){ChangeOptions()});
17
18 });
19
20 function ChangeOptions(){
21 fields = init_fields_v2();
22 var clubName = getFieldValue("Centers");
23 var myQuery = "<Eq><FieldRef Name='Centers' /><Value Type='Choice'>"+clubName+"</Value></Eq>";
24 $().SPServices.SPFilterDropdown({
25 relationshipWebURL: "",
26 relationshipList: "Courses",
27 relationshipListColumn: "Title",
28 relationshipListSortAscending: true, // Added in 2013.01
29 relationshipListSortColumn: "Title",
30 columnName: "Course",
31 listName: $().SPServices.SPListNameFromUrl(),
32 promptText: "",
33 noneText: "(None)",
34 CAMLQuery: myQuery,
35 CAMLQueryOptions: "<QueryOptions></QueryOptions>",
36 completefunc: null,
37 debug: false
38 });
39 }
40
41 </script>

Line 3 - Download spjs-utility.js from spjs.com. Among many other capabilities, the library allows you to read column values in a form, which is used on line 22
Lines 8 to 12 - Use this function to ensure that the "PCYC Club" selection column is presented as a simple dropdown. If there are more than 19 choices in that site column, then it would be presented as a "complex" dropdown, and would cause issues with line 15, which assumes that the column is rendered as a "Select" type of column in the HTML code.
Lines 14 to 16 - jquery locates the "PCYC Club" column, and attaches a function that will execute if the user changes the "PCYC Club" dropdown selection.
Line 14 - Change "PCYC Club" to the "display" name for that column in the "Participants" list.
Line 21 - Initialization code for reading column values in a form.
Line 22 - Change "Centers" to the "static" name, aka "Field Internal Name", for the "PCYC Club" column in the "Participants" list.
Line 23 - Creates a CAML query fragment that will filter the "Courses" list based on the selection in the "PCYC Club" column in the "Participants" list.
Line 23 - Change "Centers" to the "static" name for the "PCYC Club" column in the "Courses" list.
Line 26 - Change "Courses" to the name of the "Courses" list, or use its GUID, like you did in your example.
Line 27 - Change "Title" to the "static" name of the "Course" column in the "Courses" list.
Line 29 - Change "Title" to the "static" name of whichever column that you want to sort on in the "Courses" list, which will in turn sort the dropdown options in the "Course" column in the "Participants" list.
Line 30 - Change "Course" to the "display" name for that column in the "Participants" list.

This solution assumes that the "Course" column in the "Participants" list was created as a Lookup column to the "Course" column in the "Courses" list, and that you used the "PCYC Club" site column in both the lists.

Regards,

Charles

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>