Forum Discussion
Asesh Kumar Maity
Aug 12, 2019Brass Contributor
Spfx webpart to show the list of all webparts
Dear Experts, I am struggling to fulfil my requirement is that, I need to create modern SharePoint client webpart (Spfx) Which renders the list of all webpart, that exists in the current page. ...
Beau Cameron
Aug 12, 2019MVP
Asesh Kumar Maity The easiest method would be to use PnPJs Client-side page functionality. Check out the section on "Find Controls"
https://pnp.github.io/pnpjs/sp/docs/client-side-pages/
- HarshagracyFeb 10, 2020Copper ContributorThe URL is updated: https://pnp.github.io/pnpjs/sp/clientside-pages/
- Asesh Kumar MaityAug 12, 2019Brass Contributor
Is this pnpjs abblicable to classic sharepoint page in online?
Means if I create a SPfx webpart using the pnp, is it valid in Classic SharePoint Page.
Thanks
- Nov 23, 2019
no, you can't use in classic page.
btw, you can get all spfx webpart in a moder page using this method.
It require PnP/PnPJs
public async GetAllWebpart(): Promise<any[]> { // page file const file = sp.web.getFileByServerRelativePath(this.context.pageContext.site.serverRequestPath); const page = await ClientSidePage.fromFile(file); const wpData: any[] = []; page.sections.forEach(section => { section.columns.forEach(column => { column.controls.forEach(control => { var wp = { text: control.data.webPartData.title, key: control.data.webPartData.instanceId }; wpData.push(wp); }); }); }); return wpData; }Cheers,
Federico