Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge ntacheva-patch-1-1907 into production #1910

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions components/filemanager/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ The `OnRead` event fires when the data source is read. Its event handler receive
````CSHTML
@using System.IO

<TelerikFileManager Data="@FileManagerData"
@bind-Path="@DirectoryPath"
<TelerikFileManager @bind-Path="@DirectoryPath"
Height="400px"
IdField="MyModelId"
NameField="Name"
Expand All @@ -79,19 +78,18 @@ The `OnRead` event fires when the data source is read. Its event handler receive
</TelerikFileManager>

@code {
private List<FlatFileEntry> FileManagerData = new List<FlatFileEntry>();
private List<FlatFileEntry> SourceData = new List<FlatFileEntry>();

private string RootPath { get; set; } = "root-folder-path";
private string DirectoryPath { get; set; } = "root-folder-path";

private async Task OnRead(FileManagerReadEventArgs args)
{
await GetFlatFileEntries();

args.Data = FileManagerData;
args.Total = FileManagerData.Count;
await Task.Delay(500);

await Task.Yield();
//here you can pass only the files for the current directory, so you don't load the whole data collection
args.Data = SourceData;
args.Total = SourceData.Count;
}

private async Task OnUpdateHandler(FileManagerUpdateEventArgs args)
Expand All @@ -111,7 +109,7 @@ The `OnRead` event fires when the data source is read. Its event handler receive
var fullName = extension.Length > 0 && name.EndsWith(extension) ?
name : $"{name}{extension}";

var updatedItem = FileManagerData.FirstOrDefault(x => x.MyModelId == item.MyModelId);
var updatedItem = SourceData.FirstOrDefault(x => x.MyModelId == item.MyModelId);

updatedItem.Name = item.Name;
updatedItem.Path = Path.Combine(DirectoryPath, fullName);
Expand All @@ -137,10 +135,10 @@ The `OnRead` event fires when the data source is read. Its event handler receive
{
var currItem = args.Item as FlatFileEntry;

var itemToDelete = FileManagerData.FirstOrDefault(x => x.MyModelId == currItem.MyModelId);
var itemToDelete = SourceData.FirstOrDefault(x => x.MyModelId == currItem.MyModelId);

//simulate item deletion
FileManagerData.Remove(itemToDelete);
SourceData.Remove(itemToDelete);

RefreshData();
}
Expand All @@ -163,13 +161,13 @@ The `OnRead` event fires when the data source is read. Its event handler receive

private void RefreshData()
{
FileManagerData = new List<FlatFileEntry>(FileManagerData);
SourceData = new List<FlatFileEntry>(SourceData);
}

// fetch the FileManager data
protected override async Task OnInitializedAsync()
{
FileManagerData = await GetFlatFileEntries();
SourceData = await GetFlatFileEntries();
}

// a model to bind the FileManager. Should usually be in its own separate location.
Expand Down
Loading