Monday, July 14, 2008

Hiding Item Level Menu from Edit Control Block

Ok, have tried and tried and couldn't find any solid solution to disable Edit Control Block menu from a specific list. There is HideCustomAction element that can be used to disable custom actions. But this cannot be used to disable ECB menu items because ECB menu items are generetaed by JavaScript function in Core.js. There is a very good article by Liam Cleary on various options for disabling ECB menu items but they are targeted to a complete site and cannot be done for a specific list.

There is a workaround which my colleague and me came up with. But this workaround is if you want to totaly disable ECB menu for a particular list. Actually there are couple of workarounds, but its upto you which one you wanna go with (depending upon the time constraint).

First is create your own custom web part which will list all the items using SPGridView and then you can customize it as per your requirement and place that web part within a PlaceHolderMain of your custom copy of AllItems.aspx page. For this you will have to remove the View from a List Definition. This is a time consuming process and I would recommend this only if you have to do lot of customization to your ListView Webpart on AllItems page.

Second option is to use a different column to disaply Title column of a list. For any list there are three types of Title columns. a) Title b) LinkTitleNoMenu c) LinkTitle

Now it must be clear from the name of these columns , LinkTitle column is the one that is displayed by default. This column has got JavaScript functions in the ListDefinition which brings ECB menu when rendered. LinkTitleNoMenu is the column that will just display a hyperlink to DispForm.aspx to view an item. And finally Title column is the one that will display just the title without any link or ECB menu.

Now you can set any of these columns in a view of either a List Definition or from the user interface. So ,this way you can decide if you want to have a ECB menu for a particular list or not.

No comments: