2

In my SharePoint view have export excel ribbon, this is ribbon of SP standard. When click to this ribbon, I want to prompt a confirm dialog with javascript before export.

If user click OK on this dialog, system will continue the export (function of SP standard), Cancel will cancel this action.

How can this be done?

2

The solution is similar to the one I provided in this accepted answer: Attach a Javascript function to an OOTB ribbon button.

Here's the code, adopted for your case:

<CustomAction Id="TrackDownloadsAction" RegistrationType="List" RegistrationId="100" Location="CommandUI.Ribbon">
  <CommandUIExtension>
    <CommandUIDefinitions>
      <CommandUIDefinition Location="Ribbon.List.Actions.ExportToSpreadsheet">

              <Button
                Id="Ribbon.List.Actions.ExportToSpreadsheet"
                Sequence="40"
                Command="ExportToSpreadsheetIfConfirmed"
                Image16by16="/_layouts/15/$Resources:core,Language;/images/formatmap16x16.png?rev=23" Image16by16Top="-181" Image16by16Left="-73"
                Image32by32="/_layouts/15/$Resources:core,Language;/images/formatmap32x32.png?rev=23" Image32by32Top="-239" Image32by32Left="-307"
                LabelText="$Resources:core,cui_ButExportToSpreadsheet;"
                ToolTipTitle="$Resources:core,cui_ButExportToSpreadsheet;"
                ToolTipDescription="$Resources:core,cui_STT_ButExportListToSpreadsheet;"
                TemplateAlias="o2"
              />

      </CommandUIDefinition>
    </CommandUIDefinitions>
    <CommandUIHandlers>
      <CommandUIHandler
        Command="ExportToSpreadsheetIfConfirmed"
        CommandAction="javascript:if (confirm('Are you sure want to export?')) SP.Ribbon.PageManager.get_instance().executeRootCommand('ExportToSpreadsheet', window.g_CUIcommandProperties, {CommandId: 'ExportToSpreadsheet'}, null);" />
    </CommandUIHandlers>
  </CommandUIExtension>
</CustomAction>

This will replace OOTB "Export to Excel" button with the customized one for lists. If you need it for libraries, change RegistrationId to 101 and Ribbon.List.Actions.ExportToSpreadsheet to Ribbon.Library.Actions.ExportToSpreadsheet (two places in the code).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.