PnP-PowerShell icon indicating copy to clipboard operation
PnP-PowerShell copied to clipboard

Add-PnpClientSideWebPart Pick List

Open joefedorowicz opened this issue 9 years ago • 6 comments

Hello, I am unable to find the properties needed to select the list I want to display in the webpart. I can add the webpart, but cannot set the list.

Reporting an Issue or Missing Feature

Unknown. I'd assume that this can be done in the -WebPartProperties command but I am at my wits end trying to find what is expected there.

Expected behavior

Be able to set the desired list in the web part I just added.

Actual behavior

It adds a blank list web part, requiring me to pick it on the web page.

Steps to reproduce behavior

Add-PnPClientSideWebPart -DefaultWebPartType List -Page "[YOUR PAGE]"

Which version of the PnP-PowerShell Cmdlets are you using?

  • [ ] PnP PowerShell for SharePoint 2013
  • [ ] PnP PowerShell for SharePoint 2016
  • [x] PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

(you can retrieve this by executing Get-Module -Name *pnppowershell* -ListAvailable)

How did you install the PnP-PowerShell Cmdlets?

  • [ ] MSI Installed downloaded from GitHub
  • [x] Installed through the PowerShell Gallery with Install-Module
  • [ ] Other means

Thanks

joefedorowicz avatar Oct 20 '17 20:10 joefedorowicz

Hi @joefedorowicz what i've done to achieve this is to use the -WebPartProperties to set the listID:

Add-PnPClientSideWebPart -Page $clientPage -DefaultWebPartType "List" -Section 2 -Column 1 -WebPartProperties @{selectedListId="754c3e51-b7ba-4fbd-8680-fefa77330acc"}

Currently I can't find any good documentation on the properties we can set in the modern webparts, please share if anyone have a list.. ;)

This seems to work with Document Libraries also, but you need to add an extra property, as i can't figure out what the default is for a library, for SharePoint both List and Library are "List":

Add-PnPClientSideWebPart -Page $clientPage -DefaultWebPartType "List" -Section 2 -Column 2 -WebPartProperties @{isDocumentLibrary="true";selectedListId="4546de9f-af03-422f-b396-2be87f3be59d"}

JimmyHang avatar Nov 03 '17 02:11 JimmyHang

@VesaJuvonen @erwinvanhunen is there any documentation on which property we can set on which webpart? Off course for the "Default" webparts...thanks

I'll be happy to help create one, if you guys can point me in the right direction, right now i'm trying and failing by looking at the webpart controls "PropertiesJson".

JimmyHang avatar Nov 03 '17 02:11 JimmyHang

Unfortunately I'm not aware of such information/documentation

erwinvanhunen avatar Nov 19 '17 19:11 erwinvanhunen

Any one found any thing on this ?

pavan2920 avatar Jul 30 '18 06:07 pavan2920

I added a working sample for adding a list webpart over here https://github.com/SharePoint/PnP-Sites-Core/issues/2180#issuecomment-484158834

It is basically what you already figured out yourself. Note that I had to use $true instead of "true" in the web part properties.

As for a documentation of the web part properties - this would be a huge maintenance effort and risk for incorrect documentation.

The easiest thing is to configure a web part as needed and export it e.g. with Get-PnPClientSideComponent -Page $page - this lists all web parts including their properties as Json string.

heinrich-ulbricht avatar Apr 17 '19 16:04 heinrich-ulbricht

Create the json properties based on the properties of the webpart list type:

image

edisonneza avatar Aug 19 '20 15:08 edisonneza