Answered Disable Edit in Datasheet

  • Friday, May 18, 2012 3:48 PM
     
     

    Good day.

    I want programmaicaly remove ability to edit specific list in datasheet.

    I was thinking about CEWP and some code to remove Edit in Datasheet button from ribbon but i cannot find how to do that.

    Is there anyway to disable Edit in Datasheet for particular list programmatically?

    Thanks in advance.


    Best regards, Chernobrivets

All Replies

  • Friday, May 18, 2012 4:00 PM
     
     
    In the advanced list settings, there is an option to disable editing using the datasheet view.

    Bob Guidinger

  • Friday, May 18, 2012 4:36 PM
    Moderator
     
      Has Code

    Hi

    You can use a jQuery function like this: 

    <script type="text/javascript">
    $(document).ready(function() { 
       $("[text='Edit in Datasheet']").remove();
    });
    </script>
    Put the CEWP into the list's standard view and add the script above into the source, When you open the page, the edit option is gone.  Remember to include the jQuery libs into the header as well.

    Regards Bjoern
    Blog



  • Monday, May 21, 2012 6:37 AM
     
     

    Good day.

    Bjoern H Rapp

    I tried that. This works in SharePoint 2007 but not in SharePoint 2010 because the contextual tab with Edit in datasheet control not in default contextual tab.


    Best regards, Chernobrivets


  • Friday, May 25, 2012 7:02 AM
     
     Answered

    Hi Chernobrivec,

    For SharePoint 2010, DataSheetView is a ribbon button, so you can remove this button programmatically, for the way to remove it, please refer to:

    http://sharepointroot.com/2010/06/18/remove-actions-from-the-ribbon-sharepoint-2010/

    Thanks,
    Simon


    Simon Huang

    TechNet Community Support

    • Marked As Answer by Chernobrivec Friday, May 25, 2012 3:31 PM
    •  
  • Friday, May 25, 2012 3:32 PM
     
     

    Hi

    Yes, i thoght about such thing.

    But is there anyway to hide ribbon buttons using CEWP and javascript?


    Best regards, Chernobrivets

  • Friday, May 25, 2012 3:42 PM
     
     
    Even if you remove the button using JavaScript, users will still be able to edit with datasheet view (if they can do a little URL hacking).  Is there any reason you can't/don't want to disable the ability to edit in datasheet view in the advanced list settings?

    Bob Guidinger


  • Friday, May 25, 2012 4:00 PM
     
     
    Even if you remove the button using JavaScript, users will still be able to edit with datasheet view (if they can do a little URL hacking).  Is there any reason you can't/don't want to disable the ability to edit in datasheet view in the advanced list settings?

    Bob Guidinger


    Hi,

    Im okay that user will still be able to edit in datasheet. I just need to hide this button from UI.

    I've tried to use property in advanced settings but i didn't find the way to set this property programmaticaly.


    Best regards, Chernobrivets

  • Friday, May 25, 2012 4:08 PM
     
      Has Code

    Okay.  As long as you're okay with that :)

    I haven't tested this, but it should work.

    <script type="text/javascript">
      $(document).ready(function() { 
        $("#Ribbon\\.List\\.ViewFormat\\.Datasheet-Large").Remove();
      });
    </script>



    Bob Guidinger


    • Edited by Bob Guidinger Friday, May 25, 2012 4:10 PM Escaped the periods in the selector.
    •  
  • Tuesday, May 29, 2012 11:48 AM
     
     

    Nope, its not working.

    I think this is because "Edit in Datasheet" button is on List tab group which is hidden after page load.


    Best regards, Chernobrivets


  • Thursday, May 31, 2012 2:47 AM
     
      Has Code

    Yep, you're right.  The object isn't loaded into the DOM until after you click the tab in the ribbon and therefore is no accessible from jQuery.

    An easier alternative to Shimin's suggestion is to just use a custom action.  This should do it (from here):

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <CustomAction
        Id="RemoveDataSheetButton"
        Location="CommandUI.Ribbon"
        RegistrationType="List"
        RegistrationId="101">
        <CommandUIExtension>
          <CommandUIDefinitions>
            <CommandUIDefinition
              Location="Ribbon.List.ViewFormat.Datasheet" />
          </CommandUIDefinitions>
        </CommandUIExtension>
      </CustomAction>
    </Elements>



    Bob Guidinger
    Please remember to click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.