pnp / PnP

SharePoint / Office 365 Developer Patterns and Practices - Archived older solutions. Please see https://aka.ms/m365pnp for updated guidance
https://aka.ms/m365pnp
Other
1.89k stars 3.31k forks source link

Delete the existing webpart from page using SPFX #1797

Open pavan2920 opened 6 years ago

pavan2920 commented 6 years ago

Hi Team,

I have a requirement and looking for the suggestion/solution for the same.

I have a spfx webpart, which i have added in Home.aspx(modern page). This webpart has a link, on click of this link i want to Delete existing webpart(listview WP) from the current page.

Could any one suggest me how can i do the same thing.

WardWilmsen commented 6 years ago

As far as I can see there is a remove() function built into the @pnp/sp js package. Reference: https://github.com/pnp/pnpjs/blob/dev/packages/sp/src/clientsidepages.ts

So steps you need to take to achieve your solution:

  1. npm install @pnp/logging @pnp/common @pnp/odata @pnp/sp --save
  2. Use this to find the webpart you want to delete: https://github.com/pnp/pnpjs/blob/dev/packages/sp/docs/client-side-pages.md#user-content-find-controls
  3. Access the .remove() function on your control.

This should work (not tested though).