SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.24k stars 1k forks source link

By clicking the custom button of our project SPFx site page display in edit mode #9808

Open princebagthariya opened 1 month ago

princebagthariya commented 1 month ago

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

Additional environment details

Issue description

Hello Everyone,

I have created an SPFx project with React.

I want to display the SPFx site page in edit mode by clicking the custom button, not SharePoint default edit button

Can anyone help me with the same?

Tanddant commented 1 month ago

Am I understanding you correctly in that you want to be able to press a button and go into edit mode on the page?

Firstly make sure you check out the page to the user via the rest API

If you're using PnPjs that looks something like this

sp.web.getFileByServerRelativePath("/sites/dev/SitePages/Home.aspx").checkout();

Then you can enable edit mode on the page by appending the query paramater Mode=Edit

const EditPage = () => {
    let searchParams = new URLSearchParams(window.location.search);
    searchParams.set("Mode","Edit")
    window.location.search = searchParams.toString();
}

EditPage();