SharePoint Online: How to Implement Cascading Drop-down in 3 Steps?
Requirement: Cascading drop-down list in SharePoint Online.
How to Implement Cascading Lookup in SharePoint Online List Forms?
Before implementing cascading drop down in SharePoint Online lists, we need lists with data for lookup. In my case, I've three custom lists in my SharePoint Online site. Namely: Region, Country and Project Tasks. I need cascading lookup from Regions to Country drop-down in my Project Tasks list.
List 1: Region
Region list has a single column "Title" with list of regions in it.
List 2: Country
Country list has "Title" column which holds the value of the country and "Region" lookup column from "Region" list.
List 3: Project Tasks
Where the "Region" lookup column is from "Region" list and "Country" Lookup column is from "Country" List.
Step 1: Download jQuery and SPServices JavaScript Files and upload to SharePoint
Step 2: Create a Script for Cascading Lookup
Create a Text file with cascading drop down script and upload to "Site Assets" Library. Set the URL of jQuery and SPServices JavaScript files according to your environment. Set parameters for "SPCascadeDropdowns" function.
Step 3: Add Script to SharePoint Online List Forms
The final step is to link the script to list forms. Here is how:
This method of cascading drop down works in both SharePoint Online lists and libraries. Please note, this cascading doesn't work on "Quick Edit" mode. So, You may have to disable quick edit in SharePoint. Another method to implement cascading drop-down using REST APIs: https://github.com/mrackley/HillbillyCascade
Alright, How about Multi-level cascading?
Well, You can call the SPServices.SPCascadeDropdowns() function any number of times you wish with different parameters to achieve cascading to multiple fields!
How to Implement Cascading Lookup in SharePoint Online List Forms?
Before implementing cascading drop down in SharePoint Online lists, we need lists with data for lookup. In my case, I've three custom lists in my SharePoint Online site. Namely: Region, Country and Project Tasks. I need cascading lookup from Regions to Country drop-down in my Project Tasks list.
List 1: Region
Region list has a single column "Title" with list of regions in it.
List 2: Country
Country list has "Title" column which holds the value of the country and "Region" lookup column from "Region" list.
List 3: Project Tasks
Where the "Region" lookup column is from "Region" list and "Country" Lookup column is from "Country" List.
Step 1: Download jQuery and SPServices JavaScript Files and upload to SharePoint
- I've used compressed version of jQuery 3.4 from https://code.jquery.com/jquery-3.4.1.min.js
- For SPServices, go to: https://sympmarc.github.io/SPServices/SPServices.zip
Step 2: Create a Script for Cascading Lookup
Create a Text file with cascading drop down script and upload to "Site Assets" Library. Set the URL of jQuery and SPServices JavaScript files according to your environment. Set parameters for "SPCascadeDropdowns" function.
<script language="javascript" type="text/javascript" src="https://crescent.sharepoint.com/sites/marketing/2018/SiteAssets/jquery-3.4.1.min.js"></script> <script language="javascript" type="text/javascript" src="https://crescent.sharepoint.com/sites/marketing/2018/SiteAssets/jquery.SPServices.min.js"></script> <script language="javascript" type="text/javascript"> $(document).ready(function() { $().SPServices.SPCascadeDropdowns({ relationshipList: "Country", relationshipListParentColumn: "Region", relationshipListChildColumn: "Title", parentColumn: "Region", childColumn: "Country", debug: true }); }); </script>These parameters are self-explanatory! Here:
- relationshipList: "Country" : Name of the relationship list which contains parent and child columns.
- relationshipListParentColumn: "Region" : Column internal name from the relationship list (Country)
- relationshipListChildColumn: "Title" : Column internal name from the Country list
- parentColumn: "Region": Column display name from the list where the drop down is implemented.
- childColumn: "Country": Column display name from the list where the drop down is implemented.
Step 3: Add Script to SharePoint Online List Forms
The final step is to link the script to list forms. Here is how:
- Go to NewForm.aspx and EditForm.aspx pages, Click on Settings and then "Edit Page" from settings menu.
- Add a Content Editor web part, Set the Content editor web part's property to the text file with script. Under "Layout" section of web part properties, tick "Hidden" checkbox to hide the web part from user interface. Click on "Stop Editing" button once you are done with edit.
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">And Here is the cascading lookup in action:
This method of cascading drop down works in both SharePoint Online lists and libraries. Please note, this cascading doesn't work on "Quick Edit" mode. So, You may have to disable quick edit in SharePoint. Another method to implement cascading drop-down using REST APIs: https://github.com/mrackley/HillbillyCascade
Alright, How about Multi-level cascading?
Well, You can call the SPServices.SPCascadeDropdowns() function any number of times you wish with different parameters to achieve cascading to multiple fields!
No comments:
Please Login and comment to get your questions answered!