I want to use the built-in FileManagerToolBarSortTool but I want to remove the "Date Modified" option from the "Sort BY" menu.
===
ADMIN EDIT
===
For the time being, a possible option is to create a custom tool for sorting. You can use the SplitButton component to simulate the built-in UI. Upon selecting option from the dropdown, you may sort your data collection based on the selected custom sort option. Call the Rebind method to refresh the data after updating it.
__builder2.OpenComponent<TelerikUpload>(266);
__builder2.AddAttribute(267, "AutoUpload", (object?)RuntimeHelpers.TypeCheck(value: true));
__builder2.AddAttribute(268, "SaveUrl", (object?)RuntimeHelpers.TypeCheck(UploadSettings.SaveUrl));
__builder2.AddAttribute(269, "SaveField", (object?)RuntimeHelpers.TypeCheck(UploadSettings.SaveField));
__builder2.AddAttribute(270, "RemoveUrl", (object?)RuntimeHelpers.TypeCheck(UploadSettings.RemoveUrl));
__builder2.AddAttribute(271, "RemoveField", (object?)RuntimeHelpers.TypeCheck(UploadSettings.RemoveField));
__builder2.AddAttribute(272, "WithCredentials", (object?)RuntimeHelpers.TypeCheck(UploadSettings.WithCredentials));
__builder2.AddAttribute(273, "Multiple", (object?)RuntimeHelpers.TypeCheck(value: false));
__builder2.AddAttribute(274, "AllowedExtensions", RuntimeHelpers.TypeCheck(UploadSettings.AllowedExtensions));
__builder2.AddAttribute(275, "MinFileSize", RuntimeHelpers.TypeCheck(UploadSettings.MinFileSize));The FileManager TreeView does not expand automatically in some scenarios, which can cause the TreeView and ListView UI to be inconsistent:
Here is a test page and steps to reproduce.
<p>/folder-16/folder-17</p>
<TelerikTextBox @bind-Value="@DirectoryPath" Width="max-content" OnChange="@(() => FileManagerRef!.Rebind())" />
<TelerikFileManager @ref="@FileManagerRef"
Data="@FileManagerData"
@bind-Path="@DirectoryPath"
View="@FileManagerViewType.ListView"
EnableLoaderContainer="false"
OnDownload="@OnDownloadHandler"
NameField="@(nameof(FlatFileEntry.Name))"
SizeField="@(nameof(FlatFileEntry.Size))"
PathField="@(nameof(FlatFileEntry.Path))"
ExtensionField="@(nameof(FlatFileEntry.Extension))"
IsDirectoryField="@(nameof(FlatFileEntry.IsDirectory))"
HasDirectoriesField="@(nameof(FlatFileEntry.HasDirectories))"
IdField="@(nameof(FlatFileEntry.Id))"
ParentIdField="@(nameof(FlatFileEntry.ParentId))"
DateCreatedField="@(nameof(FlatFileEntry.DateCreated))"
DateCreatedUtcField="@(nameof(FlatFileEntry.DateCreatedUtc))"
DateModifiedField="@(nameof(FlatFileEntry.DateModified))"
DateModifiedUtcField="@(nameof(FlatFileEntry.DateModifiedUtc))"
Class="my-filemanager">
</TelerikFileManager>
@code {
private TelerikFileManager<FlatFileEntry>? FileManagerRef { get; set; }
private List<FlatFileEntry>? FileManagerData { get; set; }
public string? DirectoryPath { get; set; } = string.Empty;
private readonly string RootPath = string.Empty;
public async Task<bool> OnDownloadHandler(FileManagerDownloadEventArgs args)
{
await Task.Delay(1);
return true;
}
private int FolderLevelCount { get; set; } = 5;
private int FilesInFolderCount { get; set; } = 5;
private int FoldersInFolderCount { get; set; } = 2;
private int FolderNameCounter { get; set; }
private readonly List<string> FileExtensions = new() {
".txt", ".pdf", ".docx", ".xlsx", ".png", ".jpg", ".gif", ".zip", ".css", ".html", ".mp3", ".mpg"
};
protected override async Task OnInitializedAsync()
{
await Task.CompletedTask;
DirectoryPath = RootPath;
FileManagerData = LoadFlatDataAsync();
await base.OnInitializedAsync();
}
private List<FlatFileEntry> LoadFlatDataAsync()
{
List<FlatFileEntry> data = new List<FlatFileEntry>();
string rootDataPath = string.IsNullOrEmpty(RootPath) ? "/" : RootPath;
PopulateChildren(data, null, rootDataPath, 1);
return data;
}
private void PopulateChildren(List<FlatFileEntry> data, string? parentId, string parentPath, int level)
{
var rnd = Random.Shared;
for (int i = 1; i <= FilesInFolderCount; i++)
{
string itemId = Guid.NewGuid().ToString();
string itemExtension = FileExtensions[rnd.Next(0, FileExtensions.Count)];
string itemName = $"{itemExtension.Substring(1)}-file-{(FolderNameCounter != default ? string.Concat(FolderNameCounter, "-") : string.Empty)}{i}";
string itemPath = Path.Combine(parentPath, string.Concat(itemName, itemExtension));
data.Add(new FlatFileEntry()
{
Id = itemId,
ParentId = parentId,
Name = itemName,
IsDirectory = false,
HasDirectories = false,
DateCreated = DateTime.Now,
DateCreatedUtc = DateTime.Now.ToUniversalTime(),
DateModified = DateTime.Now,
DateModifiedUtc = DateTime.Now.ToUniversalTime(),
Path = itemPath,
Extension = itemExtension,
Size = rnd.Next(1_000, 3_000_000)
});
}
if (level < FolderLevelCount)
{
for (int i = 1; i <= FoldersInFolderCount; i++)
{
var itemId = Guid.NewGuid().ToString();
var itemName = $"folder-{++FolderNameCounter}";
var itemPath = Path.Combine(parentPath, itemName);
data.Add(new FlatFileEntry()
{
Id = itemId,
ParentId = parentId,
Name = itemName,
IsDirectory = true,
HasDirectories = level < FolderLevelCount - 1,
DateCreated = DateTime.Now,
DateCreatedUtc = DateTime.Now.ToUniversalTime(),
DateModified = DateTime.Now,
DateModifiedUtc = DateTime.Now.ToUniversalTime(),
Path = itemPath,
Size = rnd.Next(100_000, 10_000_000)
});
PopulateChildren(data, itemId, itemPath, level + 1);
}
}
}
public class FlatFileEntry : FileEntry
{
public string Id { get; set; } = Guid.NewGuid().ToString();
public string ParentId { get; set; }
}
public class FileEntry
{
public string Name { get; set; }
public long Size { get; set; }
public string Path { get; set; }
public string Extension { get; set; }
public bool IsDirectory { get; set; }
public bool HasDirectories { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateCreatedUtc { get; set; }
public DateTime DateModified { get; set; }
public DateTime DateModifiedUtc { get; set; }
}
}
Please expose the chunk upload settings in the FileManager Upload component through FileManagerUploadSettings.
===
TELERIK EDIT:
In the meantime, a possible workaround is to:
Three methods in Telerik.Blazor.Extensions.ReflectionExtensions call target.GetType() without first checking whether target is null. When a null object reaches any of these methods (e.g. via ConvertToFileEntry receiving a null data item), a NullReferenceException is thrown. Consider adding a null return/guard, which will prevent the exception.
Affected methods:
HasGetter
GetPropertyValue
SetPropertyValue
Proposed change:
Add an early null return/guard for target in each method, consistent with the existing null check for propertyName:
public static bool HasGetter(this object target, string propertyName)
{
if (target == null || propertyName == null)
{
return false;
}
// ...
}
public static object GetPropertyValue(this object target, string propertyName)
{
if (target == null || propertyName == null)
{
return null;
}
// ...
}
public static void SetPropertyValue(this object target, string propertyName, object value)
{
if (target == null)
{
return;
}
// ...
}Expected outcome
The FileManager crashes with a null reference exception when the selected file is deleted while the preview pane is open.
https://demos.telerik.com/blazor-ui/filemanager/overview
Error: System.NullReferenceException: Object reference not set to an instance of an object.
at System.Object.GetType()
at Telerik.Blazor.Components.TelerikFileManager`1.ConvertToFileEntry(Object dataItem)
at Telerik.Blazor.Components.TelerikFileManager`1.GetSelectedEntryForDetails()
at Telerik.Blazor.Components.TelerikFileManager`1.<BuildRenderTree>b__397_15(RenderTreeBuilder __builder3)
at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
at Telerik.Blazor.Components.TelerikSplitter.BuildRenderTree(RenderTreeBuilder __builder)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
In the FileManager in a serverc app, click the New Folder button. Try to enter folder name - depending on the server-client latency, characters may be erased as you type them. The only solution in these cases is to type slower or use a custom tool to create new folders.
The problematic behavior can also be observed when attempting to rename a file or folder through the Rename command in the built-in context menu.
(bug report only)
Regression introduced in version 14.1.0.
1. Run this example: https://blazorrepl.telerik.com/mAaNuhlQ07uvfUs053
2. Expand Work Files folder and select the Documents or Images folder.
(optional)
The FileManager does not visualize the files nested in the folders.
The FileManager visualizes the files nested in the folders.