Sometimes you create List/Document Library using Visual Studio and you need to hide ‘Export to Excel’ button from Ribbon. You do not want to do it using SharePoint Designer because you have to do it manually in all the environments. Using this JavaScript approach you can hide this button from Ribbon.
Implementation: We are going to customize the List View using JavaScript.
1. Add a JavaScript file (HideExportToExcel.js) in your solution.
2. Modify schema.xml of the List and add the reference of JavaScript file to the <JSLink> tag.
Add below code to the JavaScript file.
- var nIntervId;
-
-
- (function () {
- var e = ExecuteOrDelayUntilScriptLoaded(
- CallHide,
- "sp.js");
- })();
-
-
- function CallHide() {
- document.addEventListener('click', function (evt) {
- if (evt.target.textContent == "List") {
- nIntervId = setInterval(HideExportLink, 50);
- }
- });
- }
-
-
- function HideExportLink() {
-
- var exportSpan = document.getElementById('Ribbon.List.Actions-LargeMedium-0-0');
- if (exportSpan != null) {
-
- exportSpan.style.display = 'none';
-
- StopCallHide();
- }
- }
-
-
- function StopCallHide() {
- clearInterval(nIntervId);
- }
· Open schema.xml of ‘TestList’ and go to the AllItems View tag <View BaseViewID="1"……………>. Update the <JSLink>tag to reference this JavaScript.
-
- <JSLink>~site/Scripts/HideExportToExcel.js</JSLink>