SharePoint的列表进行2级以上的分组的方法.docx
《SharePoint的列表进行2级以上的分组的方法.docx》由会员分享,可在线阅读,更多相关《SharePoint的列表进行2级以上的分组的方法.docx(12页珍藏版)》请在冰豆网上搜索。
![SharePoint的列表进行2级以上的分组的方法.docx](https://file1.bdocx.com/fileroot1/2023-2/3/eb154e8e-b70f-4bfd-aa90-3c463cfe7728/eb154e8e-b70f-4bfd-aa90-3c463cfe77281.gif)
SharePoint的列表进行2级以上的分组的方法
SharePoint:
GroupByonmorethan2columnsinaview(SP2010)
ThisisanupdateofanarticlewrittenforSharePoint2007.Manyofthestepsarethesameinboth2007and2010,butboththeSharePointDesignerstepsandthedefaultwebpartusedforviewshavechanged.
GroupByonmorethan2columnsinaview
InmySharePointclassesIhaveoftenbeenofaskedhowtogrouponmorethantwolevelsinaview.Ihavealwaysgiventhequickanswerof"useSharePointDesigner"!
But,someofyouhaveasked"How?
".Youmaybesorryyouasked…butheregoes…
Goals:
∙Createaviewwithnestedgroupsdeeperthanjust2levels
∙Putthecountsandtotalsatthebottomofeachsection.
∙Dotheabovewithnocustomwebparts,customXSLToranythingthathastobedeployedtotheserver.
Sample:
SecretsandTricksneeded:
∙Itcan'tbedone"outofthebox"inthebrowser
∙SharePointDesignerisneededtomaketheedits
∙YouneedtoconverttheviewwebparttoaSharePointDesignerDataFormWebPart
∙YouneedaSortandGroupsecret
∙Youneedtofixthefooterrows
∙Youneedtomanuallyaddyourtotals,averages,countsetc.
Warning!
SharePoint2010doesnotconsiderapagewithaDataFromWebParttobea“view”.Itonlybelievesthatapageisa“view”whenithasan“XsltListViewWebPart”.In2007wecouldcreateanewview,edititinSharePointDesignerasmuchaswewanted,anditwasstillaview.In2010,SharePointwillnotrecognizeapagewithoutaXsltListViewWebPartasaview.
Sobeforeyoustart…
∙Ifyoujustneedapagewithyourlistnicelygrouped,itmaybebestjusttocreateawebpartpageandstoreitinalibrary.ThenaddtheDataFormWebPartusingthestepsbelow.
∙Ifyouwantthepagetobetreatedasaview,leavetheXsltListViewWebPartonthepage,butmakeithidden.ThenaddtheDataFormWebPartbelowtheexistingwebusingthestepsbelow.
oInSP2010,aviewpagewithanaddedwebpartintroducesabugortwo.Theribbonwillnotbedisplayed.Theviewdropdowninthepagetitleareawillbemissingthedropdowntoselectanotherview.
MyExample:
∙Ihaveasimplelist(actuallyimportedfromExcel)withthesecolumns:
ID1,Bike,BikeType,BikeSize,BikeColorandRetail(price).
∙IwanttogroupthisonBikeType,BikeSize,BikeColorandcounttheitemsandsumoraveragethepriceineachgroup.
CreateanewStandardViewfromthelist'sviewmenu.
Don'tbotherwithanyoptionsaswearejustgoingtodeletethedefaultlistwebpart.
Orjustcreateanemptywebpartpage.(see“Warning”above)
The“before”–justastandardviewwithselectedcolumns:
Ifusinganexistingviewpage:
∙OpenyoursitewithSharePointDesignerandclicktheListsandLibrariesnodeintheSiteObjectspane
∙Clickyourlist(“Bikes”inmyexample)
∙Clickyourviewyoucreatedearlier(“Grouped”inmyexample)
Otherwisecreateanewwebpartpageinalibrary
∙Notes(backgroundonly,youcanskipthis):
oTheviewisnowbeingdisplayedusingaXsltListViewWebPart(ItwasaListViewWebPartinSP2007)andcanonlybecustomizedwiththesameoptionsasfoundusingabrowser("ModifyView")
oTheXsltListViewWebParthasthesamegroupinglimitationsandtheListViewWebPart(2levelsofgrouping)
oFormoreinfoonwhathaschangedfromthe2007ListViewWebPartandtheXsltListViewWebPartseeand
oSharePointDesigner2010hastwowebpartsforlists:
▪XsltListViewWebPart-thisisthewebpartusedwhenyoucreateanewView
▪DataFormWebPart–createdfromSharePointDesignerusingInsert,EmptyDataView
oSPD2010addsabitofconfusionwhentryingtoadda“DataView”
▪WhenyouclickInsert,(pickanexistinglist)SPDinsertsanXsltListViewWebPart
▪WhenyouclickInsert,EmptyDataViewSPDinsertsaDataFormWebPart
∙Ifstartingwithanexistingview,deleteorhidetheexistingwebpart.
oDelete:
IntheDesignwindowclickinthewebpart,clicktheWebPartPages:
XsltListViewWebParttab,presstheDeletekey
or
intheCodewindowselecttheentireXsltListViewWebParttag(includingthestartandendtags)anddeletethecode
oHide:
IntheDesignwindowclickinthewebpart.IntheRibbonintheListViewToolssectionclicktheWebParttabandthenclickProperties.IntheLayoutssectionofpropertiesclickHidden
∙InsertanEmptyDataViewWebpart
oClicktheInsertRibbontabandclicktheDataViewbutton
oClickEmptyDataView
oInthenewwebpartclick“Clickheretoselectadatasource”
oClickyourlistandclickOK(thiswillopentheDataSourceDetailsPane)
oSelectthecolumnsyouwantinyourlist(clickafield,thenShift-clickeachadditionalfield)
oClickthe“InsertSelectedFieldsas”buttonandclick“MultipleItemView”
Note:
IfyoufollowedtheearlierarticleforSharePoint2007,therestofthestepsareprettymuchthesame.
Note:
theviewisnowbeingdisplayedusingaDataFormWebPartand:
∙isnolongera“View”andcannotlongerbemodifiedfromthebrowser
∙canbecustomizedfromSharePointDesigner,
∙fromthebrowseryoucanonlyrenametheview,
∙fromthebrowseryoucanalsouseSiteActions,EditPage,ModifySharedWebParttohandedittheXSLT,;-)
∙goingforward,columnsaddedtothelistwillnotbeautomaticallyaddedtotheDataFormWebPart.YouwillneedtouseSharePointDesignertomanuallyaddthecolumnstothe“view’.
Save!
AtthispointyoumaywanttoclickSaveandreviewtheresultssofarinabrowser.Reviewtheformattingandnotethethingsyouneedtochange.
∙EdittheDataViewWebPart
∙ClickthewebpartandnotethatyounowhaveDataViewToolssectionintheSharePointDesignerribbon.
∙Click“SortandGroup”
∙RemoveanysortfieldsthatmayalreadybeintheSortOrdercolumn
Addyourtopmostgroup:
oClickthefield(BikeType)and
oClickAdd
oClick“Showgroupheader”
oClick“Collapsegroupbydefault”(optional)
oClick“Showgroupfooter”(ifyouwantcountsandtotals)
Addyoursecondgroupbyclickingthefield(Example:
Size)andclickingAdd.
∙Ifyoustophereyouwillhavegroups,butallofyourcountsandtotalswillbewrong!
Weneedtocreateboththetexttodisplayforthegroupandahierarchyforthegrouping.Atthesecondlevelofourgroupingweneedtogrouponthecombinationofbothcolumns,“BikeType”plus“Size”
∙Click“EditSortExpression”
oAtaminimumyouwillneedtoconcatenatethecurrentgroupingcolumnwiththepreviousgroupingcolumns,andwhileyouareatityoucanaddsome“pretty”formatting:
oEnter:
concat(@Bike_x0020_Type,"-",@Size)(Watchthecapitalization!
UsetheexactnametheIntelisenseoffers–spacesare“coded”so“BikeType”is“Bike_x0020_Type”.)
oNotethepreviewatthebottomofthedialogbox…
oClickOK
oClickShowgroupheader
oClickCollapsegroup(optional)
oClickShowgroupfooter(ifyouwantcountsandtotals)
∙ Forthethirdandfollowinggroups-repeatthestepabovewithSortExpressionssimilarto:
∙concat(@Bike_x0020_Type,"-",@Size,"-",@Bike_x0020_Color)
∙Morecolumns?
Ineachnewgroupincludeallofthefieldsfromthepreviousgroupsalongwithanyseparatorsyoulike:
concat(@group1field,@group2field,@group3field,@group4field,@group5field,etc)
orconcat(@group1field,"-",@group2field,"-",@group3field,"-",@group4field,"-",@group5field,etc)
∙Ifyoucouldseethefullwidthoftheseyouwouldsee:
∙ BeforeclickingOKtoleavethisdialogbox,checktheorderofthegroups.Theyhaveprobablygottenchanged.(bug?
)
∙Makesuretheyareinordersomethinglike:
@BikeType
concat(@Bike_x0020_Type,"-",@Size)
concat(@Bike_x0020_Type,"-",@Size,"-",@Bike_x0020_Color)
∙Recheckeachofthesortlevelstoseeifthesearestillchecked:
oClickShowgroupheader
oClickCollapsegroup(optional)
oClickShowgroupfooter(ifyouwantcountsandtotals)
∙ Optionallyaddonemorecolumnjusttosortthedatawithinthelastgroup.Donotturnonthegroupheaderorgroupfooteroptionsforthissort-onlyfield.
∙ ClickOKtoclosetheSortandGroupdialogbox.
∙ YouwillprobablywanttochangethePagingoptionsastheydefaultto10items.ClickthePagingbuttonintheRibbon(DataViewToolsgroup,Optiontab)
∙ Tip:
IfyouhavealotofdatainthelistSharePointDesignercangetreallyslow.Therearetwothingsyoucoulddohere,setpagingtoasmallnumber(notsogoodfortestingmulti-levelgrouping)orfromtheCommonControlTasksselectShowWithSampleData.
∙ IfyouwantgrandtotalsyouwillalsoneedtoclickDataViewPropertiesandcheckShowViewFooter.
∙ Save!
AtthispointyoumaywanttoclickSaveandreviewtheresultssofarinabrowser.Youshouldnowhaveallofyourgroups.
Clickthe+toexpandasection.
∙ Nowisagoodtimetocleanuptheformattingsuchasthegraybackgroundandoddrowheightinthegroupheaderandfooterrows.(Right-clickintherowinDesignviewandselectCellProperties.
(clickforbiggerview)
∙ Yourgroupingworkisnowdone.Thefollowingstepsareonlyneededifyouwanttoaddtotals,counts,averages,etc.
∙ Nowfortotals!
∙Thesestepsdescribeaddingtotalstothefooterrows,butalsoapplytomodifyingheader(topofeachgroup)rows.
∙TheDataViewsetsuptheheaderandfooterrowsasasinglecellwithacolumnspanof99!
Todisplaytotalsinthesamecolumnsandthedatayouwillneedtofixtheserows.
∙Youwillneedtofixeachofthegroupfooterrowsplustheviewfooterrow.
∙ Inthe