I'm just new to reactjs-spfx controls. I have a pnpjs control that lists all the pages and it's contents. I should be able to add edit and delete pages using that web part. I want to include in that component the functionality to add a new Web part to the page content when I'm editing it. How do you call that functionality from SharePoint to add new webpart? Please see below picture. Thanks.
Asked
Active
Viewed 140 times
0

Sol
- 53
- 7
1 Answers
1
I would recommend using pnpjs library for this, it wraps most basic tasks with a nice api. I am adding my own webpart to a page something like this, just to give you an idea:
See https://pnp.github.io/pnpjs/sp/clientside-pages/
const sp = SPFI(...)
// or get the existing page
const page = await sp.web.addClientsidePage(fileName, title);
const section = page.addSection();
const partDefs = await sp.web.getClientsideWebParts();
// find the web part we want to add by guid
const myPartDef = partDefs.find(c => areGuidsEqual(c.Id, MY_GUID));
const part = ClientsideWebpart.fromComponentDef(myPartDef);
part.setProperties({
someProp: someValue
});
section.addControl(part);
await page.save();

Nikolay
- 10,752
- 2
- 23
- 51
-
Thanks. I'll try this. I'll mark your answer later. This might be the answer I 'm looking for. – Sol Oct 07 '22 at 16:20
-
your answer is partly right but I want to directly call the SharePoint Add webpart dialog box See pic.https://drive.google.com/file/d/1bX8cqaYBcUvzL9lFg67IPIcgMmcSmXfk/view?usp=drivesdk – Sol Oct 10 '22 at 05:15
-
That is not possible of course. this dialog is a part of sharepoint product itself – Nikolay Oct 10 '22 at 07:11