This article has been VERY useful. But I wanted something lightly different: I wanted to add a custom action, but also have the “EDIT” button (but not the “SHARE”), and to use the current item info for my custom action.
Here is the result:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | // add a special callout action for our library SP.SOD.executeFunc( "callout.js" , "Callout" , function () { var itemCtx = {}; itemCtx.Templates = {}; itemCtx.BaseViewID = 'Callout' ; // Define the list template type itemCtx.ListTemplateType = 101; itemCtx.Templates.Footer = function (itemCtx) { // context, custom action function, show the ECB menu (boolean) return CalloutRenderFooterTemplate(itemCtx, AddCustomAction, true ); }; SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx); }); function AddCustomAction (renderCtx, calloutActionMenu) { var itemIndex = renderCtx.CurrentItemIdx // Add your custom action calloutActionMenu.addAction( new CalloutAction ({ text: "Custom Action" , tooltip: 'This is your custom action' , onClickCallback: function () { // all the data related to your item are into `renderCtx.ListData.Row[itemIndex]` console.log( 'Callback from custom action' ); } })); // re-add EDIT action calloutActionMenu.addAction( new CalloutAction ({ text: "Edit" , onClickCallback: function (event) { // use the default action we have when clicking on the filename into the library // or call the EditForm if it's a list item and not a library DispEx( this , event,'TRUE ',' FALSE ',' FALSE ',' SharePoint.OpenDocuments.3 ',' 1 ',' SharePoint.OpenDocuments ',' ',' 1https: //your.sharepoint.com/_layouts/15/WopiFrame.aspx?sourcedoc='+renderCtx.ListData.Row[itemIndex].FileRef+'&action=default','','1','0','0','0x7fffffffffffffff') } })); } |