Few months ago, I was asked, “Is it possible to restrict the users (even with sufficient privileges to add, edit, delete items) from Editing, adding, deleting the items using ‘Edit in DataSheet‘ option” because the application had a Custom Form for Add and Edit and those forms had some validations. It is very obvious that with Edit in DataSheet Form all it prompts you for are very few validations such as Required Field, DataType etc, but does not support validation depending on two colums.
I felt this would make a very interesting post. Also, I believe this is a very common requirement many customers would like to have it. My first option as always (as most of them would expect as per my previous posts) was to have a javascript fucntion to implement this.
- Add a Content Editor WebPart to the Lists “All Items.aspx” page, where you would have the option “Edit in DataSheet”, Export to Spread Sheet” etc under Actions Tab.
- In the Content Editor WebPart Click Edit –> Modify Shared WebPart –> Source Editor — Paste the below Script.
<html>
<head>
<script type=”text/javascript” language=”javascript”>
HideDataSheet();
function HideDataSheet()
{
var vMenu = document.getElementsByTagName(‘menu’);
for(var k = 0; k < vMenu.length; k++)
{
var vMenuItem = vMenu[k].getElementsByTagName(‘ie:menuitem’);
for(var i = 0; i < vMenuItem.length; i++)
{
if(vMenuItem[i].getAttribute(“text”) == “Edit in Datasheet” || vMenuItem[i].getAttribute(“text”) == “Export to Spreadsheet“)
{
vMenuItem[i].setAttribute(“hidden”,true);
}
}
}
}
</script>
</head>
<body>
</body>
</html>
- Save the Content and click OK.
Now When you click on Actions Tab you will observe that the two options “Export to Spread Sheet”, “Edit in DataSheet” no longer appear.
This script is tested across different browsers: IE, Firefox, Chrome and it works as expected. However, Please note that you wouldn’t be seeing the Option “Edit in DataSheet” in browsers other than IE even without the above script as there is a default script which checks if the browser is IE or not.
Similarly, this script can be used to hide any other Sub menus. Please make sure that you replace the Title you are looking for with the one marked in Red.
A few more queries and its resolution with respect to this feature in my next Post.
Thank you!
Undoubtedly. All things are difficult before they are easy 🙄
That is true Arianna!
Hi,
This code is working perfectly for all the links except “Open With Access”, I need to hide open with access link from actions menu.
Is there any other way to hide the link [open with access]?
Thanks In Advance,
Komal.
Hi Komal,
You are correct this does not work for “Open With Access”. Try adding an else if condition the code
if(vMenuItem[i].getAttribute(“text”) == “Edit in Datasheet” || vMenuItem[i].getAttribute(“text”) == “Export to Spreadsheet“)
{
vMenuItem[i].setAttribute(“hidden”,true);
}
else if(vMenuItem[i].hasattribute(“textScript”))
{
if(vMenuItem[i].getAttribute(“textScript”) == “javascript:databaseBtnText”)
{
vMenuItem[i].setAttribute(“hidden”,true);
}
}
I believe this should work. Let me know if this works I’ll update my post with this and Thanks for bringing this up.
why it does not work for me?
Jun,
May I know compete details? What is that you are trying to achieve and does not work?
Does this work in SP 2007? I don’t seem to be able to get it to work. I have infopath form sending data to SP. I added a CEWP above my items lists, but the edit datasheet option continues to appear for user with contribute permissions. Thanks!
Hi David,
Sorry I couldn’t visit your comment earlier, somehow I missed it out. It does work SharePoint 2007. The current code is not restricted based on permissions, so whatever maybe the permissions of the user it would still disable it.
1) Verify if the javascript function is firing (by having some alert messages in the code)?
2) Try adding the CEWP below the list
3) In the master page change “defer” attribute to “true” (refer my first blog for more details on this)
Hope this helps!
Thanks,
Venkat