ECB Menu For SharePoint or Custom action menu is available for user access at different locations in SharePoint. It can be an icon/text, which can be used to implement functionality such as navigating to a landing page, starting a Workflow on an item or any custom action inside SharePoint.
ECB Menu can be created using SP designer as well as Jquery. If usign designer, go to list/library then under custom action, click create new button and provide the page URL appended with "?ID={ItemId}", if we want to pass current item ID.
By default SharePoint provides the default custom action like edit, delete and view item options.
Here we will be adding new ECB Menu as "Custom Edit Page" as shown in the below image.
On click of the Cusom Edit Link, it will be redirected to my custom edit page which I have created under list form.
Also, I am passing the ID of current list item as well as Source page URL from where it will be redirected back after performing action on redirected edit page.
Implementaion
It can be implemented with any list/library, however I have implemented it on list.
You can use any ScriptEditor/CEWP on your page and put all below scripts as is by just changing the list name and URL.
Note: The ECB Menu by default will open in next tab, but if we want to open the link in current tab, it can be done by putting below script in SharePoint designer under Navigate to URL option.
javascript:(function() {var items = SP.ListOperation.Selection.getSelectedItems(); window.location.href= "http://sites/QA/SL_MI/Lists/ComplainTracking/CustomEditPage.aspx?ID={ItemId}";})()
Full Script
- <script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
- <script language="javascript" type="text/javascript">
- $(document).ready(function() {
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', AddCustomUserActionToECB);
- });
-
- function AddCustomUserActionToECB() {
- var clientContext = new SP.ClientContext();
- var oWeb = clientContext.get_web();
- var oList = oWeb.get_lists().getByTitle('ComplainTracking');
- var userCustomActionColl = oList.get_userCustomActions();
- clientContext.load(oList, 'UserCustomActions', 'Title');
- clientContext.executeQueryAsync(function() {
- var customActionEnumerator = userCustomActionColl.getEnumerator();
- var foundAction = 0;
- while (customActionEnumerator.moveNext()) {
- var oUserCustomAction = customActionEnumerator.get_current();
- if (oUserCustomAction.get_title() == 'Custom Edit Page') {
-
-
-
- foundAction = 1;
- break;
- }
- }
- if (foundAction == 0) {
- var oUserCustomAction = userCustomActionColl.add();
- oUserCustomAction.set_location('EditControlBlock');
- oUserCustomAction.set_sequence(100);
- oUserCustomAction.set_title("Custom Edit Page");
-
- oUserCustomAction.set_url("/sites/QA/SL_MI/Lists/ComplainTracking/Edit1.aspx?ID={ItemId}&Source=/sites/QA/SL_MI/SitePages/ListViewGrid.aspx");
- oUserCustomAction.update();
- clientContext.load(userCustomActionColl);
- clientContext.executeQueryAsync();
- }
- }, function(sender, args) {
- console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
- });
- }
- </script>