开发者

Creating a hierarchical dropdown list from a sharepoint list

开发者 https://www.devze.com 2023-03-01 02:31 出处:网络
I\'m trying to take data from a SharePoint list that is of the form: ID, Title, Parent_ID, some other stuff that isn\'t of consequence.

I'm trying to take data from a SharePoint list that is of the form:

ID, Title, Parent_ID, some other stuff that isn't of consequence.

1, GroupA, null  
2, GroupB, null  
3, GroupC, null  
4, ASubA, 开发者_JAVA百科1  
5, ASubB, 1  
6, BSubA, 2  
7, CSubA, 3  
8, CSubB, 3  
9, CSubC, 3

I want to translate this cleanly to a dropdown on a webpart that would look like:

Show All

 GroupA

  ASubA

  ASubB

 GroupB

  BSubA

 GroupC

  CSubA

  CSubB

  CSubC

I can throw this together with some recursion and some DataTable merging, but it will be confusing and more difficult to maintain for the next person who comes along. I'm looking for a smooth way of accomplishing this. I feel like I should be able to accomplish this with some GroupBy in a CAML Query, but I haven't been doing SharePoint for too long.

Is there some hierarchical data structure I could stick this all into, and then pull it back out in order? Or some Query Syntax that I'm not thinking of?

Thanks in advance.


Instead of a Parent_ID, why don't you use a Group_ID:

1, GroupA, 1
2, GroupB, 2
3, GroupC, 3
4, ASubA, 1
5, ASubB, 1
6, BSubA, 2
7, CSubA, 3
8, CSubB, 3
9, CSubC, 3

You can now sort by Group_ID in your query.

Alternately, you could use two lists, one for groups, and the second for subs with a lookup column.


Which version of SharePoint are you using? If you are using SharePoint 2010, instead of creating your own, I would recommend using Managed Metadata:

Managed metadata is a hierarchical collection of centrally managed terms that you can define, and then use as attributes for items in Microsoft SharePoint Server 2010.


Another idea: merge columns 3 and 1, and sort by the resulting value
GroupA, 1
ASubA, 14
ASubB, 15
GroupB, 2
BSubA, 26
GroupC, 3
CSubA, 37
CSubB, 38
CSubC, 39
(Alphabetical sorting on numbers)

Of course, you'll need to insert some zeros if you have a longer list.

0

精彩评论

暂无评论...
验证码 换一张
取 消