Customize the "This Folder is empty" view
Hi
When a folder is empty is shows a big folder icon and the text "This folder is empty".
I have a special folder that gets the files from an Api. When the Api is not accessible (offline) I'd like to show a offline icon and the text "Offline". It should also not be possible to drop files.
How can I show full customized content in the icon and the details view? Can you provide a sample?
Thanks in advance for your help.
Regards, Bruno
OnSuccess event of the FileManager to toggle a CSS class based on the response status and path. We have attached a sample demonstrating how to:- Dynamically apply an
fm-offline-stateclass when the folder is empty and the API is in an offline state. - Use CSS to override the default icon and text with your custom "Offline" view.
<div> <SfFileManager TValue="FileManagerDirectoryContent" CssClass="@EmptyStateClass" @ref="fileManager"> ... <FileManagerEvents TValue="FileManagerDirectoryContent" OnSuccess="Success" > </FileManagerEvents> </SfFileManager> </div> @code { public string path = "/tvy/"; SfFileManager<FileManagerDirectoryContent> fileManager; public string EmptyStateClass; private void Success(SuccessEventArgs<FileManagerDirectoryContent> args) { var currentpath = fileManager.Path; if (args.Action == "read" && currentpath == path && args.Result.Files.Count == 0 && args.Result.CWD.HasChild == false) { EmptyStateClass = "fm-offline-state"; } else { EmptyStateClass = string.Empty; } } } <style> .fm-offline-state .e-empty-icon{ background-image: none; } .fm-offline-state .e-empty-icon::before { content: "\e878"; font-family: "e-icons"; font-size: 40px; color: #6b7280; display: block; text-align: center; margin-top: 48px; } .fm-offline-state .e-empty-content { position: relative; color: transparent !important; font-size: 0 !important; } .fm-offline-state .e-empty-content::before { content: "Offline"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #374151; font-size: 18px; font-weight: 600; } </style> |
- Would you like to prevent external drag-and-drop uploads into that folder?
- Or are you aiming to restrict the drag-and-drop movement of existing files or folders within the component?
Regards,
Praveen Sellappan
Attachment: FileSample_e815e3bb.zip
Hi Praveen
Thank you for your code snipped! I works like a charm.
I would also disable all OS drag-drop uploads and internal moves into offline folders since I can do nothing with the file while connection to the API is off.
Can you provide me short sample code?
Regards,
Bruno
<SfFileManager TValue="FileManagerDirectoryContent" CssClass="@EmptyStateClass" @ref="fileManager" AllowDragAndDrop="true"> ...... <FileManagerEvents TValue="FileManagerDirectoryContent" OnSuccess="Success" OnFileDragStop="FileDragStop"> </FileManagerEvents> </SfFileManager> @code { ....... private void Success(SuccessEventArgs<FileManagerDirectoryContent> args) { var currentpath = fileManager.Path; if (args.Action == "read" && currentpath == path && args.Result.Files.Count == 0 && args.Result.CWD.HasChild == false) { EmptyStateClass = "fm-offline-state"; IsSpecailFolder = args.Result.CWD.Name; filterpath = args.Result.CWD.FilterPath; } else { EmptyStateClass = string.Empty; IsSpecailFolder = ""; filterpath = ""; } } public void FileDragStop(FileDragEventArgs<FileManagerDirectoryContent> args) { if (EmptyStateClass == "fm-offline-state" && IsSpecailFolder == args.DropTargetDetail.Name && filterpath == args.DropTargetDetail.FilterPath) { args.Cancel = true; } } } |
Regards,
Praveen Sellappan
Attachment: FileDND_97c91bfc.zip
Hi Praveen
I used a Interop solution for preventing drag/drop.
It shows a not allowed cursor if drop is not possible. Thats less
confusing for the user. I call the two functions in the Success event
window.fileManagerUtils = { // prevent external drag-and-drop preventExternalDrop: function (elementId) { const el = document.getElementById(elementId); if (!el) return; el._preventDrop = function (e) { if (e.dataTransfer && e.dataTransfer.types.includes('Files')) { e.preventDefault(); e.stopPropagation(); e.dataTransfer.dropEffect = 'none'; } }; el.addEventListener('dragover', el._preventDrop, true); el.addEventListener('drop', el._preventDrop, true); }, allowExternalDrop: function(elementId) { const el = document.getElementById(elementId); if (!el || !el._preventDrop) return; el.removeEventListener('dragover', el._preventDrop, true); el.removeEventListener('drop', el._preventDrop, true); delete el._preventDrop; } };
I also supressed the text "Drag files here to upload" by the following css-class:
.e-filemanager.so-fm-offline .e-empty-inner-content { font-size: 0 !important; color: transparent !important; }
Do you think that these two measures are ok?
Regards, Bruno
Praveen Sellappan
- 5 Replies
- 2 Participants
-
BR Bruno
- Jun 2, 2026 04:28 PM UTC
- Jun 16, 2026 02:30 PM UTC