SharePoint Filtered Lookup Column in a List[Sharepoint过滤选项字段,无代码]
来源:互联网 发布:李健老婆孟小蓓 知乎 编辑:程序博客网 时间:2024/05/22 11:55
https://www.mriwm.com/Public/PamBlog/Lists/Posts/Post.aspx?ID=39
Out of the box no way currently exists in SharePoint to filter a lookup column to show only a subset of entries based on certain criteria. I found this post which got me most of the way to a solution but thought I would add a few points for clarification with screenshots as below.
One thing to note is that if you modify the New and Edit forms, you will subsequently break attachments. There is a hotfix to address the attachment issue but it requires deployment to the server and adds work to your modifications. In my next post I will show you how to filter a lookup using javascript which keeps attachments intact and avoids the entire hotfix issue.
Here's how to create a filtered lookup column:
- To start with create two lists where one is the lookup list (MyLookupList) and one is the list that would use the lookup list as a lookup column (Math Classes Offered). The names of my lists are in parenthesis for clarification.
- DON'T SKIP THIS STEP - In the list ("Math Classes Offered") that will use the lookup list (MyLookupList) create a Single Line of Text column and NOT a Lookup column. If you use a Lookup column, you will get an error when trying to save new or updated entries.
- In SharePoint Designer go to the Data Source Library tab. Right click on the lookup list (MyLookupList) and select Copy and Modify…
- In the Data Source Properties popup window, on the General tab enter the Name (FilteredLookup).
On the Source tab under Query click on the Filter button and enter your Filter Criteria. Click Ok. You may also want to set the Fields by clicking on the Fields button (for best performance, reduce the fields to only those needed) and the Sort by clicking on the Sort button. Click Ok.
- On the Data Source Library tab right click on your newly created FilteredLookup from step 3 above and select Save As… Navigate to a location on your local machine and save the file (FilteredLookup.xml).
- Open the local file saved in step 4 (FilteredLookup.xml) in a text editor.
- Add { } around each of the 4 guids ( ="{17CFFB4F-665F-4F7F-9914-7DCE51312962}" )
- Add an id attribute right after the UseInternalName attribute and give it a value (id="FilteredLookup")
- Save the file with your updates but keep the file open
- Copy the text only from the starting to ending SharePoint:SPDataSource tags. Mine looks like below but yours will be different based on your list guid, the fields, sort, and filter values…
<SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" id="FilteredLookup" selectcommand="<View><Query><Where><Eq><FieldRef Name="SubjectCanTeach"/><Value Type="Text">Math</Value></Eq></Where></Query><ViewFields><FieldRef Name="Title"/><FieldRef Name="SubjectCanTeach"/><FieldRef Name="ID"/><FieldRef Name="PermMask"/></ViewFields></View>"><SelectParameters><asp:Parameter Name="ListID" DefaultValue="{17CFFB4F-665F-4F7F-9914-7DCE51312962}" /></SelectParameters><DeleteParameters><asp:Parameter Name="ListID" DefaultValue="{17CFFB4F-665F-4F7F-9914-7DCE51312962}" /></DeleteParameters><UpdateParameters><asp:Parameter Name="ListID" DefaultValue="{17CFFB4F-665F-4F7F-9914-7DCE51312962}" /></UpdateParameters><InsertParameters><asp:Parameter Name="ListID" DefaultValue="{17CFFB4F-665F-4F7F-9914-7DCE51312962}" /></InsertParameters></SharePoint:SPDataSource>
- Before starting this step always back up any files you will be editing. In SharePoint Designer, open the file you will be editing such as EditForm.aspx or NewForm.aspx file. This step will allow you to get to the individual list columns to edit them.
- Hide the existing List Form Web Part by changing the IsVisible property to false for <IsVisible>false</IsVisible> in code view.
- Place your cursor directly after the hidden List Form Web Part and add another List Form Web Part by clicking Insert/SharePoint Controls/ Custom List Form…
- Choose your list and form type. Click Ok.
- In the code view of your form search for the tag <DataSources>
- After the entry for the existing <SharePoint:SPDataSource … and before the closing </DataSources> tag, paste in the copied SPDataSource from step 6.
- Your code should look something like this:
- Setup your SharePoint environment to be in Split mode. In Design View select the column that will be used for the lookup field. Right now it will show as a textbox. In Code View the associated code for the textbox will be highlighted. Comment out the textbox.
- Add the following code right after the commented out textbox and then modify the values in bold to match your particular list:
<SharePoint:DVDropDownList runat="server" id="ff5{$Pos}" DataSourceID="FilteredLookup" DataTextField="Title" DataValueField="Title" SelectedValue="{@MathTeachers}" __designer:bind="{ddwrt:DataBind('u',concat('ff5',$Pos),'SelectedValue','SelectedIndexChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@MathTeachers')}"/>
Change
Explanation
ff5
This should be the same ff# as what was commented out for the text field
@MathTeachers
See the value of text= as was commented out for the text field
FilteredLookup
The name of your lookup list datasource which is what was entered as the id (step 6)
u
u or I where u=edit mode and i= new mode
DataTextField="Title"
Change Title as necessary to match the field from the Lookup List (MyFilteredLookup)
DataValueField="Title"
Change Title as necessary to match the value from the Lookup List (MyFilteredLookup)
11. Those are all the steps you need.
12. Any time you need to update your filter (for example sorting the items or changing criteria), you can always go back into the properties of your copied datasource, make your change, save locally, copy out the select command and paste into your new datasource on the page.
- SharePoint Filtered Lookup Column in a List[Sharepoint过滤选项字段,无代码]
- sharepoint list 设置中column没有排序选项
- Sharepoint lookup字段的关联列表查询
- SharePoint 2010: Lookup column在SQL里面的最大限制
- SharePoint: In a CAML query, filter by lookup item ID, not by its value
- Custom Sharepoint Lookup Field
- SharePoint 读取选项字段所有Choise
- 继续之前的Sharepoint Lookup
- SharePoint 创建 Lookup 类型的Site Column解决跨站问题
- SharePoint 创建 Lookup 类型的Site Column解决跨站问题
- SharePoint 创建 Lookup 类型的Site Column解决跨站问题
- 转:How to submit the rows of a repeating table in InfoPath to a SharePoint list
- Example for updating list in Sharepoint 2010
- Creating a Custom SharePoint 2007 List Definition
- Create a dialog in Sharepoint 2010
- How to only display "This Week" items in a SharePoint List
- How to delete a large number of data in SharePoint for List when refreshing data?
- sharepoint 创建自定义字段
- 我学编程之我学我鉴
- struct stat 的用法
- MediaScannerReceiver
- linux 下的文件操作
- ubuntu 提示no such device grub rescue> 的解决方法,简单
- SharePoint Filtered Lookup Column in a List[Sharepoint过滤选项字段,无代码]
- Hadoop下进行反向索引(Inverted Index)操作
- Java语法总结 - 内部类
- 就这么进来了
- java分布式通信系统(J2EE分布式服务器架构)
- 新手加入
- 收藏的关于博客园网站(增加中)
- UV
- 我看风寒感冒和风热感冒