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

Sortable List Component #636

Merged
merged 20 commits into from
Apr 6, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Sortable List - demos updated
gvreddy04 committed Apr 3, 2024
commit a96793abf1d4a87b2af1d88b122a43e73fbc9fda
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<SortableList Class="mb-3" TItem="Employee" Data="items" Context="item" IsLoading="isLoading">
<SortableList Class="mb-3"
TItem="Employee"
Data="employees"
Context="item"
IsLoading="isLoading"
OnUpdate="@OnEmployeeListUpdate">
<ItemTemplate>
@item.Name
</ItemTemplate>
@@ -8,20 +13,28 @@

@code {
public bool isLoading = false;
public List<Employee> items = null!;
public List<Employee> employees = null!;

private async Task LoadDataAsync()
{
isLoading = true;
await Task.Delay(3000);
items = Enumerable.Range(1, 5).Select(i => new Employee { Id = i, Name = $"Item {i}" }).ToList();
employees = Enumerable.Range(1, 5).Select(i => new Employee(i, $"Employee {i}")).ToList();
isLoading = false;
await base.OnInitializedAsync();
}

public class Employee
private void OnEmployeeListUpdate(SortableListEventArgs args)
{
public int Id { get; set; }
public string? Name { get; set; }
var itemToMove = employees[args.OldIndex];

employees.RemoveAt(args.OldIndex);

if (args.NewIndex < employees.Count)
employees.Insert(args.NewIndex, itemToMove);
else
employees.Add(itemToMove);
}

public record Employee(int Id, string? Name);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<SortableList TItem="Employee" Data="items" Context="item">
<SortableList TItem="Employee"
Data="items"
Context="item">
<ItemTemplate>
@item.Name
</ItemTemplate>
@@ -7,9 +9,5 @@
@code {
public List<Employee> items = null!;

public class Employee
{
public int Id { get; set; }
public string? Name { get; set; }
}
public record Employee(int Id, string? Name);
}
Loading