@@ -21,6 +21,7 @@ This article explains the events available in the Telerik FileManager for Blazor
21
21
* [ Other Events] ( #other-events ) - other events the grid provides.
22
22
* [ OnModelInit] ( #onmodelinit )
23
23
* [ OnDownload] ( #ondownload )
24
+ * [ SelectedItemsChanged] ( #selecteditemschanged )
24
25
25
26
## CUD Events
26
27
@@ -328,28 +329,37 @@ The `OnModelInit` event fires when a new instance of the model is about to be cr
328
329
329
330
The ` OnDownload ` event fires before a file is to be downloaded, cancellable. Its event handler receives the updated ` FileManagerDownloadEventArgs ` as an argument. See the [ example] ( #example ) .
330
331
332
+ ### SelectedItemsChanged
333
+
334
+ The ` SelectedItemChanged ` event fires every time the user clicks on a new file/folder in the main pane of the FileManager. You can use it with one-way binding of the ` SelectedItems ` parameter to respond to user selection.
335
+
331
336
## Example
332
337
333
338
> caption Handle FileManager events.
334
339
335
340
```` CSHTML
336
341
@using System.IO
337
342
338
- <TelerikFileManager Data="@Data "
343
+ <TelerikFileManager Data="@Files "
339
344
@bind-Path="@DirectoryPath"
340
345
Height="400px"
341
346
OnCreate="@OnCreateHandler"
342
347
OnUpdate="@OnUpdateHandler"
348
+ OnDelete="@OnDeleteHandler"
343
349
OnModelInit="@OnModelInitHandler"
344
350
OnDownload="@OnDownloadHandler"
345
- OnDelete="@OnDeleteHandler">
351
+ SelectedItems="@SelectedItems"
352
+ SelectedItemsChanged="@((IEnumerable<FlatFileEntry> selectedFiles) => OnSelect(selectedFiles))">
346
353
</TelerikFileManager>
347
354
348
355
@code {
349
- public List<FlatFileEntry> Data = new List<FlatFileEntry>();
350
- public string DirectoryPath { get; set; } = string.Empty;
356
+ private List<FlatFileEntry> Files = new List<FlatFileEntry>();
357
+
358
+ private string DirectoryPath { get; set; } = string.Empty;
351
359
352
- async Task OnCreateHandler(FileManagerCreateEventArgs args)
360
+ private IEnumerable<FlatFileEntry> SelectedItems { get; set; } = new List<FlatFileEntry>();
361
+
362
+ private async Task OnCreateHandler(FileManagerCreateEventArgs args)
353
363
{
354
364
var newFolder = args.Item as FlatFileEntry;
355
365
@@ -373,35 +383,35 @@ The `OnDownload` event fires before a file is to be downloaded, cancellable. Its
373
383
{
374
384
// simulate add in file system
375
385
newFolder.ParentId = parentDirectory.Id;
376
- Data .Add(newFolder);
377
- parentDirectory.HasDirectories = Data .Count(x => x.ParentId == parentDirectory.Id) > 0;
386
+ Files .Add(newFolder);
387
+ parentDirectory.HasDirectories = Files .Count(x => x.ParentId == parentDirectory.Id) > 0;
378
388
}
379
389
else
380
390
{
381
391
// create a folder in the root dir
382
- Data .Add(newFolder);
392
+ Files .Add(newFolder);
383
393
}
384
394
385
395
RefreshData();
386
396
}
387
397
388
398
private FlatFileEntry GetDirectory(string path)
389
399
{
390
- var directory = Data .FirstOrDefault(x => x.IsDirectory && x.Path == path);
400
+ var directory = Files .FirstOrDefault(x => x.IsDirectory && x.Path == path);
391
401
392
402
return directory;
393
403
}
394
404
395
405
private FlatFileEntry GetParent(FlatFileEntry currItem, string currDirectory)
396
406
{
397
- var parentItem = Data
407
+ var parentItem = Files
398
408
.FirstOrDefault(x => x.IsDirectory && x.Path == currDirectory);
399
409
400
410
return parentItem;
401
411
}
402
412
403
413
404
- async Task OnUpdateHandler(FileManagerUpdateEventArgs args)
414
+ private async Task OnUpdateHandler(FileManagerUpdateEventArgs args)
405
415
{
406
416
var item = args.Item as FlatFileEntry;
407
417
@@ -418,15 +428,15 @@ The `OnDownload` event fires before a file is to be downloaded, cancellable. Its
418
428
var fullName = extension.Length > 0 && name.EndsWith(extension) ?
419
429
name : $"{name}{extension}";
420
430
421
- var updatedItem = Data .FirstOrDefault(x => x.Id == item.Id);
431
+ var updatedItem = Files .FirstOrDefault(x => x.Id == item.Id);
422
432
423
433
updatedItem.Name = item.Name;
424
434
updatedItem.Path = Path.Combine(DirectoryPath, fullName);
425
435
Console.WriteLine(updatedItem.Path);
426
436
}
427
437
}
428
438
429
- async Task OnDownloadHandler(FileManagerDownloadEventArgs args)
439
+ private async Task OnDownloadHandler(FileManagerDownloadEventArgs args)
430
440
{
431
441
var selectedItem = args.Item as FlatFileEntry;
432
442
@@ -441,13 +451,13 @@ The `OnDownload` event fires before a file is to be downloaded, cancellable. Its
441
451
}
442
452
443
453
444
- async Task OnDeleteHandler(FileManagerDeleteEventArgs args)
454
+ private async Task OnDeleteHandler(FileManagerDeleteEventArgs args)
445
455
{
446
456
var currItem = args.Item as FlatFileEntry;
447
457
448
- var itemToDelete = Data .FirstOrDefault(x => x.Id == currItem.Id);
458
+ var itemToDelete = Files .FirstOrDefault(x => x.Id == currItem.Id);
449
459
450
- Data .Remove(itemToDelete);
460
+ Files .Remove(itemToDelete);
451
461
452
462
RefreshData();
453
463
}
@@ -468,15 +478,21 @@ The `OnDownload` event fires before a file is to be downloaded, cancellable. Its
468
478
return item;
469
479
}
470
480
481
+ private void OnSelect(IEnumerable<FlatFileEntry> selectedFiles)
482
+ {
483
+ //update the view-model
484
+ SelectedItems = selectedFiles;
485
+ }
486
+
471
487
private void RefreshData()
472
488
{
473
- Data = new List<FlatFileEntry>(Data );
489
+ Files = new List<FlatFileEntry>(Files );
474
490
}
475
491
476
492
// fetch the FileManager data
477
493
protected override async Task OnInitializedAsync()
478
494
{
479
- Data = await GetFlatFileEntries();
495
+ Files = await GetFlatFileEntries();
480
496
}
481
497
482
498
// a model to bind the FileManager. Should usually be in its own separate location.
0 commit comments