Pages

Monday, May 8, 2017

Get SharePoint ribbon actions outside using pagestatecommands


SharePoint facilitating a framework to re-use the ribbon actions outside in a page layout. Like to edit, save, publish, discard changes. Find the below example code snippet below to use the page state commands,

var mgr = SP.Ribbon.PageManager.get_instance();
if(mgr && (mgr.get_commandDispatcher()).isCommandEnabled('PageStateGroupSaveAndStop')) {
(mgr.get_commandDispatcher()).executeCommand('PageStateGroupSaveAndStop', null);
sessionStorage.setItem('SAVE','saved');
}
return CancelEvent(event);


Above code is to save the page without using ribbon action and outside of it. You can include above code in button click and which will execute based on context of the page. While using page state commands, make sure "Show and Hide Ribbon" option selected to "No" in Navigation of site. Also make sure SP.Ribbon.js file loaded before execute the commands code.

Please refer list of page state commands available with clear explanation in msdn article: https://msdn.microsoft.com/en-us/library/office/ee551465(v=office.14).aspx







No comments:

Post a Comment